diff options
| author | krolyxon <krolyxon@tutanota.com> | 2022-08-26 12:23:04 +0530 |
|---|---|---|
| committer | krolyxon <krolyxon@tutanota.com> | 2022-08-26 12:23:04 +0530 |
| commit | 79ac1db3380d0cc89784f50823e1f4642d03e0ed (patch) | |
| tree | 584fdc2efd07f3b5c46bc2df2e23f54f95835568 /.local/bin | |
| parent | 9acd363b84fe523c1205221761faadfd52f64a25 (diff) | |
sbar
Diffstat (limited to '.local/bin')
| -rwxr-xr-x | .local/bin/sbar | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/.local/bin/sbar b/.local/bin/sbar new file mode 100755 index 0000000..3a2b109 --- /dev/null +++ b/.local/bin/sbar @@ -0,0 +1,77 @@ +#!/bin/env sh + +# INIT +printf "$$" > ~/.cache/pidofbar +sec=0 + +# MODULES +update_cpu () { + cpu=" $(grep -o "^[^ ]*" /proc/loadavg )" +} + +update_memory () { + memory=" $(free -h | sed -n "2s/\([^ ]* *\)\{2\}\([^ ]*\).*/\2/p")" +} + +update_time () { + time="$(date "+[ %a %d %b ] [ %I:%M %P ]")" +} + +update_weather () { + weather=" $(curl -s "wttr.in?format=1" | awk '{printf $2}')" +} + +# update_bat () { +# # you might need to change the path depending on your device +# read -r bat_status </sys/class/power_supply/BAT1/status +# read -r bat_capacity </sys/class/power_supply/BAT1/capacity +# bat="$bat_status $bat_capacity%" +# } + +update_vol () { + vol="$([ "$(pamixer --get-mute)" = "false" ] && printf ' ' || printf ' ')$(pamixer --get-volume)%" +} + +# For calcurse users, refer https://github.com/pystardust/automeet +#update_event () { +# event="$(calcurse -n | sed 1d | \ +# sed -E "s_^ *\[(.*):(.*)\] ([^\t]*)\t?.*_[\1h \2m->\3]_")" +# [ "[]" = "$event" ] && event="" +#} + + +# modules that don't update on their own need to be run at the start for getting their initial value +update_vol + +display () { + #printf "%s\n" " $event [$weather] [$memory $cpu] [$bat] [$backlight] [$vol] $time " + xsetroot -name " [ $weather ] [ $memory $cpu ] [ $vol ] $time " +} + +# SIGNALLING +# trap "<function>;display" "RTMIN+n" +trap "update_vol;display" "RTMIN" +# trap "update_bat;display" "RTMIN+2" +# to update it from external commands +## kill -m "$(cat ~/.cache/pidofbar)" +# where m = 34 + n + +while true +do + sleep 1 & wait && { + # to update item ever n seconds with a offset of m + ## [ $((sec % n)) -eq m ] && udpate_item + [ $((sec % 5 )) -eq 0 ] && update_time # update time every 5 seconds + [ $((sec % 5)) -eq 0 ] && update_cpu # update cpu every 15 seconds + [ $((sec % 15)) -eq 0 ] && update_memory + # [ $((sec % 60)) -eq 0 ] && update_bat + [ $((sec % 3600)) -eq 2 ] && update_weather + #[ $((sec % 300)) -eq 1 ] && update_event + + # how often the display updates ( 5 seconds ) + [ $((sec % 5 )) -eq 0 ] && display + sec=$((sec + 1)) + } +done + + |
