diff options
author | Xiao Pan <gky44px1999@gmail.com> | 2024-02-23 03:08:52 -0800 |
---|---|---|
committer | Xiao Pan <gky44px1999@gmail.com> | 2024-02-23 03:08:52 -0800 |
commit | dd78faaf40862bd1552ec36c41374b527f747284 (patch) | |
tree | b914f890c545db7168984f7bcc15cfc7c976c1d3 /sh/sbar | |
parent | c808bb6ee7f77f077308a1f06f63dbee6a928f6d (diff) |
Reorganize shell scripts into sh dir, consider in the future fsh will have different kinds of files
Diffstat (limited to 'sh/sbar')
-rwxr-xr-x | sh/sbar | 79 |
1 files changed, 79 insertions, 0 deletions
@@ -0,0 +1,79 @@ +#!/bin/sh +# modified from pystardust, GPLv3 license: https://github.com/pystardust/sbar + +# INIT +sec=0 + +# MODULES +update_time () { + time="$(date '+%a %m/%d %H:%M') $(TZ=Asia/Shanghai date '+/%d %H:') $(date -u '+/%d %H:')" +} + +#update_cap () { +# cap="$(if xset q | grep -q "Caps Lock: *on"; then echo A; else echo a; fi)" +#} + +update_net () { + net="$(if nmcli -t --fields type,state device | grep -q '^\(ethernet\|wifi\):connected$'; then echo 1; else echo 0; fi)" + nm_device_state="$(nmcli -t --fields device,state device)" + vpn="$( + if echo "$nm_device_state" | grep -q '^wg_ka:connected$'; then + echo K + elif echo "$nm_device_state" | grep -q '^wg_studio:connected$'; then + echo S + else + echo 0 + fi + )" +} + +update_vol () { + # $(NF-1) for both alsa and pulseaudio + vol="$(amixer get Master | awk -F'[][]' 'END{printf("%d %s",($(NF-1)=="on")?1:0,$2)}')" +} + +update_mic () { + # $(NF-1) for both alsa and pulseaudio + mic="$(amixer get Capture | awk -F '[][]' 'END{print ($(NF-1)=="on")?1:0}')" +} + +update_bat () { + bat="$(cat /sys/class/power_supply/BAT0/capacity)%" +} + +update_gpu () { + gpu="$(envycontrol -q | awk 'END{print toupper(substr($NF,0,1))}')" +} + +display () { + xsetroot -name "$time | N $net V $vpn | M $vol C $mic | $gpu | $bat" +} + +# modules that don't update on their own need to be run at the start for getting their initial value +update_net +update_vol +update_mic +update_gpu + +# SIGNALLING +# trap "<function>;display" "RTMIN+n" +trap "update_mic;display" "RTMIN" +trap "update_vol;display" "RTMIN+1" +# xev can't read my toggle internet keyboard key, don't know what key to use in sxhkd to send signal +trap "update_net;display" "RTMIN+2" +# to update it from external commands +## kill -m $(pidof -x sbar) +# where m = 34 + n + +while :; do + sleep 1 & + wait + [ $((sec % 5 )) -eq 0 ] && update_time # update time every 5 seconds + [ $((sec % 60)) -eq 0 ] && update_net + [ $((sec % 60)) -eq 0 ] && update_bat + # zoom turn on my mic on start, so need to monitor the change + [ $((sec % 60 )) -eq 0 ] && update_mic + # how often the display updates ( 5 seconds ) + [ $((sec % 5 )) -eq 0 ] && display + sec=$((sec + 1)) +done |