remove a few scripts, and move all monitors to a single script

This commit is contained in:
frosty 2024-07-04 17:01:41 -04:00
parent 676b63cd79
commit 71949de0f7
15 changed files with 122 additions and 168 deletions

View file

@ -7,12 +7,12 @@ Config
, template = " %XMonadLog% }{ %network% <fc=#777777>:</fc> VOL %volume% <fc=#777777>:</fc> %battery% <fc=#777777>:</fc> CPU %cpu% <fc=#777777>:</fc> RAM %memory% <fc=#777777>:</fc> %load% <fc=#777777>:</fc> <fc=#f7e83b>%date%</fc> "
, commands =
[ Run XMonadLog
, Run Com "netmon" [] "network" 6000
, Run Com "monitors" ["network"] "network" 6000
, Run PipeReader "/tmp/pipe-volume" "volume"
, Run Com "batmon" [] "battery" 36000
, Run Com "cpumon" [] "cpu" 50
, Run Com "memmon" [] "memory" 50
, Run Com "loadmon" [] "load" 6000
, Run Com "monitors" ["battery"] "battery" 36000
, Run Com "monitors" ["cpu"] "cpu" 50
, Run Com "monitors" ["memory"] "memory" 50
, Run Com "monitors" ["load"] "load" 6000
, Run Date "%d/%m/%Y %H:%M:%S" "date" 10
]
}

View file

@ -1,16 +0,0 @@
#!/bin/sh
FULL_THRESHOLD=80
FULL_COLOR="#31f53e"
read -r capacity </sys/class/power_supply/BAT1/capacity
read -r status </sys/class/power_supply/BAT1/status
if [ "$capacity" -ge "$FULL_THRESHOLD" ] && [ "$status" = "Not charging" ]; then
status="Full"
fi
if [ "$status" = "Full" ]; then
printf '<fc=%s>%s%%</fc> (%s)\n' "$FULL_COLOR" "$capacity" "$status"
else
printf '%s%% (%s)\n' "$capacity" "$status"
fi

View file

@ -1,29 +0,0 @@
#!/bin/sh
while read -r _ user _ system idle _; do
initial_user_sys=$((user + system))
initial_total=$((user + system + idle))
break
done </proc/stat
sleep 1
while read -r _ user _ system idle _; do
current_user_sys=$((user + system))
current_total=$((user + system + idle))
break
done </proc/stat
while read -r line; do
case $line in
*Package\ id\ 0:*) temp=$line ;;
esac
done <<EOF
$(sensors)
EOF
temp=${temp#Package id 0:*+}
temp=${temp%%°*}
temp=${temp%.*}
printf '%s°C (%.*f%%)\n' "$temp" 0 $(((current_user_sys - initial_user_sys) * 100 / (current_total - initial_total)))

View file

@ -1,7 +0,0 @@
#!/bin/sh
location=${1:-/}
[ -d "$location" ] || exit
df -h "$location" | awk ' /[0-9]/ {print $3 "/" $2}'

View file

@ -1,7 +0,0 @@
#!/bin/sh
address=$(ip route get 1)
address=${address#* via * dev * src }
address=${address% uid *}
printf '%s\n' "$address"

View file

@ -1,9 +0,0 @@
#!/bin/sh
while read -r one five fifteen _; do
load_one=$one
load_five=$five
load_fifteen=$fifteen
done </proc/loadavg
printf '%s %s %s\n' "$load_one" "$load_five" "$load_fifteen"

View file

@ -1,21 +0,0 @@
#!/bin/sh
convert_to_human_readable() {
if [ "$1" -lt 1024 ]; then
printf "%.1fK\n" "$1"
elif [ "$1" -lt 1048576 ]; then
printf "%.1fM\n" $(($1 / 1024))
else
printf "%.1fG\n" $(($1 / 1048576))
fi
}
while read -r label size _; do
case $label in
MemTotal:) total_mem=$size ;;
MemAvailable:) free_mem=$size ;;
esac
done </proc/meminfo
used_mem=$((total_mem - free_mem))
printf '%s (%s%%)\n' "$(convert_to_human_readable "$used_mem")" $((used_mem * 100 / total_mem))

116
.local/bin/monitors Executable file
View file

@ -0,0 +1,116 @@
#!/bin/sh
BATTERY_FULL_THRESHOLD=80
BATTERY_FULL_COLOR="#31f53e"
WIFI_ADAPTER="wlan0"
readable_kib() {
if [ "$1" -lt 1024 ]; then
printf "%.1fK\n" "$1"
elif [ "$1" -lt 1048576 ]; then
printf "%.1fM\n" $(($1 / 1024))
else
printf "%.1fG\n" $(($1 / 1048576))
fi
}
monitor_battery() {
read -r capacity </sys/class/power_supply/BAT1/capacity
read -r status </sys/class/power_supply/BAT1/status
if [ "$capacity" -ge "$BATTERY_FULL_THRESHOLD" ] && [ "$status" = "Not charging" ]; then
status="Full"
fi
if [ "$status" = "Full" ]; then
printf '<fc=%s>%s%%</fc> (%s)\n' "$BATTERY_FULL_COLOR" "$capacity" "$status"
else
printf '%s%% (%s)\n' "$capacity" "$status"
fi
}
monitor_cpu() {
while read -r _ user _ system idle _; do
initial_user_sys=$((user + system))
initial_total=$((user + system + idle))
break
done </proc/stat
sleep 1
while read -r _ user _ system idle _; do
current_user_sys=$((user + system))
current_total=$((user + system + idle))
break
done </proc/stat
while read -r line; do
case $line in
*Package\ id\ 0:*) temp=$line ;;
esac
done <<EOF
$(sensors)
EOF
temp=${temp#Package id 0:*+}
temp=${temp%%°*}
temp=${temp%.*}
printf '%s°C (%.*f%%)\n' "$temp" 0 $(((current_user_sys - initial_user_sys) * 100 / (current_total - initial_total)))
}
monitor_load() {
while read -r one five fifteen _; do
load_one=$one
load_five=$five
load_fifteen=$fifteen
done </proc/loadavg
printf '%s %s %s\n' "$load_one" "$load_five" "$load_fifteen"
}
monitor_memory() {
while read -r label size _; do
case $label in
MemTotal:) total_mem=$size ;;
MemAvailable:) free_mem=$size ;;
esac
done </proc/meminfo
used_mem=$((total_mem - free_mem))
printf '%s (%s%%)\n' "$(readable_kib "$used_mem")" $((used_mem * 100 / total_mem))
}
monitor_network() {
address=$(ip route get 1)
address=${address#* via * dev * src }
address=${address% uid *}
ssid=
while read -r line; do
case $line in
*Connected\ network*)
ssid=${line##*Connected network}
ssid="${ssid#"${ssid%%[![:space:]]*}"}"
;;
esac
done <<EOF
$(iwctl station "$WIFI_ADAPTER" show)
EOF
printf '<fc=#fc7932>%s</fc> @ %s\n' "$address" "$ssid"
}
monitor_volume() {
volume=$(wpctl get-volume @DEFAULT_AUDIO_SINK@)
volume=${volume% \[MUTED\]}
volume=${volume#Volume: }
volume=${volume%.*}${volume#*.}
volume=${volume#0}
printf '%s%%\n' "$volume"
}
if command -v monitor_"$1" >/dev/null 2>&1; then
monitor_"$1"
fi

View file

@ -1,21 +0,0 @@
#!/bin/sh
ADAPTER="wlan0"
address=$(ip route get 1)
address=${address#* via * dev * src }
address=${address% uid *}
ssid=
while read -r line; do
case $line in
*Connected\ network*)
ssid=${line##*Connected network}
ssid="${ssid#"${ssid%%[![:space:]]*}"}"
;;
esac
done <<EOF
$(iwctl station "$ADAPTER" show)
EOF
printf '<fc=#fc7932>%s</fc> @ %s\n' "$address" "$ssid"

View file

@ -1,8 +0,0 @@
#!/bin/sh
TEXT_COLOR="#fe8019"
PIPE_FILE="/tmp/pipe-nowplaying"
[ -p "$PIPE_FILE" ] || mkfifo "$PIPE_FILE"
echo "<fc=$TEXT_COLOR>$(mpc | head -n1)</fc>" >"$PIPE_FILE"

View file

@ -3,4 +3,4 @@
PIPE_FILE="/tmp/pipe-volume"
[ -p "$PIPE_FILE" ] || mkfifo "$PIPE_FILE"
volmon >"$PIPE_FILE"
monitors volume >"$PIPE_FILE"

View file

@ -1,17 +0,0 @@
#!/bin/sh
ADAPTER="wlan0"
ssid=
while read -r line; do
case $line in
*Connected\ network*)
ssid=${line##*Connected network}
ssid="${ssid#"${ssid%%[![:space:]]*}"}"
;;
esac
done <<EOF
$(iwctl station "$ADAPTER" show)
EOF
printf '%s\n' "$ssid"

View file

@ -1,15 +0,0 @@
#!/bin/sh
while read -r line; do
case $line in
*Package\ id\ 0:*) temp=$line ;;
esac
done <<EOF
$(sensors)
EOF
temp=${temp#Package id 0:*+}
temp=${temp%%°*}
temp=${temp%.*}
printf '%s°C\n' "$temp"

View file

@ -1,3 +0,0 @@
#!/bin/sh
uptime -p | sed 's/up //; s/,//g'

View file

@ -1,9 +0,0 @@
#!/bin/sh
volume=$(wpctl get-volume @DEFAULT_AUDIO_SINK@)
volume=${volume% \[MUTED\]}
volume=${volume#Volume: }
volume=${volume%.*}${volume#*.}
volume=${volume#0}
printf '%s%%\n' "$volume"