Update scripts

This commit is contained in:
2025-04-07 11:05:18 +01:00
parent ca8a63edcd
commit 62343c2157
5 changed files with 83 additions and 16 deletions

33
scripts/battery Executable file
View File

@@ -0,0 +1,33 @@
#! /bin/bash
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"
MAGENTA="\e[35m"
CYAN="\e[36m"
BOLD="\e[1m"
ENDCOLOR="\e[0m"
BATTERY_INFO=$(upower -i $(upower -e | grep 'BAT'))
BATTERY_PERCENT=$(echo "$BATTERY_INFO" | grep -oP 'percentage:\s+\K\d+')
BATTERY_STATUS=$(echo "$BATTERY_INFO" | grep -oP 'state:\s+\K\w+')
CHARGE_CYCLES=$(echo "$BATTERY_INFO" | grep -oP 'cycle-count:\s+\K\d+')
WARNING_LEVEL=$(echo "$BATTERY_INFO" | grep -oP 'warning-level:\s+\K\w+')
if [ "$BATTERY_STATUS" == "charging" ] || [ "$BATTERY_STATUS" == "pending" ]; then
COLOR=$CYAN
elif [ "$BATTERY_PERCENT" -ge 80 ]; then
COLOR=$GREEN
elif [ "$BATTERY_PERCENT" -ge 30 ]; then
COLOR=$YELLOW
else
COLOR=$RED
fi
echo -e "${BOLD}Battery: ${COLOR}$BATTERY_PERCENT% ($BATTERY_STATUS)${ENDCOLOR}"
if [ -n "$CHARGE_CYCLES" ]; then
echo -e "${BOLD}Charge Cycles: ${MAGENTA}$CHARGE_CYCLES${ENDCOLOR}"
fi
if [ "$WARNING_LEVEL" != "none" ]; then
echo -e "${BOLD}Warning Level: ${RED}$WARNING_LEVEL${ENDCOLOR}"
fi

View File

@@ -1,6 +1,12 @@
#!/bin/sh #!/bin/sh
# Script to display CPU usage # Script to display CPU usage
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"
CYAN="\e[36m"
ENDCOLOR="\e[0m"
# Cache in tmpfs to improve speed and reduce SSD load # Cache in tmpfs to improve speed and reduce SSD load
cache=/tmp/cpu-script-cache cache=/tmp/cpu-script-cache
rm /tmp/cpu-script-cache 2>/dev/null rm /tmp/cpu-script-cache 2>/dev/null
@@ -8,21 +14,30 @@ while true; do
sleep 1 sleep 1
cpu_stats=$(awk '/^cpu / {print $2 + $3 + $4 + $5, $5}' /proc/stat) cpu_stats=$(awk '/^cpu / {print $2 + $3 + $4 + $5, $5}' /proc/stat)
if [ ! -f "$cache" ]; then if [ ! -f "$cache" ]; then
printf "  ---%% \r" echo -n "  ${CYAN}--%${ENDCOLOR} \r"
echo "$cpu_stats" >"$cache" echo "$cpu_stats" >"$cache"
continue continue
fi fi
prev_stats=$(cat "$cache") prev_stats=$(cat "$cache")
echo "$cpu_stats $prev_stats" | awk '{ total=$(echo "$prev_stats" | awk '{print $1}')
total_diff = $1 - $3 prev_idle=$(echo "$prev_stats" | awk '{print $2}')
idle_diff = $2 - $4 curr_total=$(echo "$cpu_stats" | awk '{print $1}')
if (total_diff == 0) { curr_idle=$(echo "$cpu_stats" | awk '{print $2}')
usage = 0 total_diff=$((curr_total - total))
} else { idle_diff=$((curr_idle - prev_idle))
usage = 100 * (1 - idle_diff / total_diff)
} if [ "$total_diff" -eq 0 ]; then
printf "  %.1f%% \r", usage usage=0 # Avoid division by zero
exit else
}' usage=$((100 * (total_diff - idle_diff) / total_diff))
fi
if [ "$usage" -lt 50 ]; then
echo -n "  ${GREEN}${usage}%${ENDCOLOR} \r"
elif [ "$usage" -lt 70 ]; then
echo -n "  ${YELLOW}${usage}%${ENDCOLOR} \r"
else
echo -n "  ${RED}${usage}%${ENDCOLOR} \r"
fi
echo "$cpu_stats" >"$cache" echo "$cpu_stats" >"$cache"
done done

View File

@@ -20,7 +20,8 @@ echo -e "${CYAN}OS:${ENDCOLOR} $OS $ARCH"
# Host Model # Host Model
HOST_MODEL=$(cat /sys/class/dmi/id/product_name 2>/dev/null) HOST_MODEL=$(cat /sys/class/dmi/id/product_name 2>/dev/null)
echo -e "${CYAN}Host:${ENDCOLOR} ${HOST_MODEL}" HOST_VERSION=$(cat /sys/class/dmi/id/product_version 2>/dev/null)
echo -e "${CYAN}Host:${ENDCOLOR} ${HOST_VERSION} (${HOST_MODEL})"
# Kernel version # Kernel version
echo -e "${CYAN}Kernel:${ENDCOLOR} Linux $(uname -r)" echo -e "${CYAN}Kernel:${ENDCOLOR} Linux $(uname -r)"

View File

@@ -1,3 +1,22 @@
#!/bin/sh #!/bin/bash
free --mebi | sed -n '2{p;q}' | awk '{printf (" %.1f%%\n", ($4/$2)*100)}' RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"
ENDCOLOR="\e[0m"
mem_info=$(free | awk '/Mem:/ {print $2, $3}')
read total used <<<"$mem_info"
percent=$(awk "BEGIN {printf \"%.0f\", ($used/$total)*100}")
if [ "$percent" -le 60 ]; then
percent_color=$GREEN
elif [ "$percent" -le 80 ]; then
percent_color=$YELLOW
else
percent_color=$RED
fi
mem_total=$(free -h | awk '/Mem:/ {print $2}')
mem_used=$(free -h | awk '/Mem:/ {print $3}')
echo -e " ${mem_used} / ${mem_total} (${percent_color}${percent}%${ENDCOLOR})"

View File

@@ -1,4 +1,3 @@
#! /bin/bash #! /bin/bash
paste <(cat /sys/class/thermal/thermal_zone*/type) <(cat /sys/class/thermal/thermal_zone*/temp) | column -s $'\t' -t | sed 's/\(.\)..$/.\1°C/' paste <(cat /sys/class/thermal/thermal_zone*/type) <(cat /sys/class/thermal/thermal_zone*/temp) | column -s $'\t' -t | sed 's/\(.\)..$/.\1°C/'