feat: bash

This commit is contained in:
ange 2024-06-23 11:51:38 +02:00
parent 937ab54f8c
commit 7ae0b331cf
Signed by: ange
GPG key ID: 9E0C4157BB7BEB1D
30 changed files with 517 additions and 65 deletions

View file

@ -35,7 +35,7 @@ function update_sink_vol() {
sink_vol='🔇'
return
fi
vol="$(awk '{print int($2 * 100)}' <<< "$sink")"
vol="$(awk '{printf "%.0f", $2 * 100}' <<< "$sink")"
{ [ "$vol" -gt 67 ] && sink_vol=" $vol"; } ||
{ [ "$vol" -gt 33 ] && sink_vol=" $vol"; } ||
{ sink_vol=" $vol"; }
@ -49,18 +49,18 @@ function update_source_vol() {
source_vol=''
return
fi
source_vol=" $(awk '{print int($2 * 100)}' <<< "$source")"
source_vol=" $(awk '{printf "%.0f", $2 * 100}' <<< "$source")"
}
function update_wlp() {
local sig ssid dev=wlan0
sig="$(awk "/$dev/{print int(\$3)}" /proc/net/wireless)"
sig="$(awk "/$dev/{printf \"%.0f\", \$3}" /proc/net/wireless)"
if [ -z "$sig" ]; then
wlp='⚠'
return
fi
ssid="$(networkctl status "$dev" | grep -Po 'Wi-Fi access point:\s*\K\w+')"
ssid="$(networkctl status "$dev" --json=short | jq -r .SSID)"
{ [ "$sig" -gt 56 ] && wlp="▂▄▆█ $ssid"; } ||
{ [ "$sig" -gt 38 ] && wlp="▂▄▆_ $ssid"; } ||
{ [ "$sig" -gt 21 ] && wlp="▂▄__ $ssid"; } ||
@ -69,7 +69,11 @@ function update_wlp() {
}
function update_time() {
time="$(date "+%a %m-%d %R")"
time="$(date '+%a %m-%d %R')"
}
function reload() {
sec=0
}
function display() {
@ -84,8 +88,9 @@ fi
# SIGNALING
# trap '<function>;display;wait' 'RTMIN+n'
trap 'update_sink_vol;display;wait' 'RTMIN'
trap 'update_wlp;display;wait' 'RTMIN+1'
trap 'reload' 'RTMIN'
trap 'update_sink_vol;display;wait' 'RTMIN+1'
trap 'update_wlp;display;wait' 'RTMIN+2'
# to update it from external commands
## kill -m "$(cat ~/.cache/pidofbar)"
# where m = 34 + n
@ -94,19 +99,18 @@ echo "$$" > "$HOME/.cache/pidofbar"
sec=0
while true; do
wait && {
[ "$((sec % 300))" = 10 ] && update_crypto
[ "$((sec % 10))" = 0 ] && {
update_cpu
update_memory
update_sink_vol
update_source_vol
update_wlp
update_bat
update_time
display
}
sec="$((sec + 10))"
[ "$((sec % 300))" = 10 ] && update_crypto
[ "$((sec % 10))" = 0 ] && {
update_cpu
update_memory
update_sink_vol
update_source_vol
update_wlp
update_bat
update_time
display
}
sec="$((sec + 10))"
awk "@load \"time\"; BEGIN {d=10; s=$(date '+%S.%N'); sleep(d - s % d)}" &
wait
done