Krolyxon
Commit 79ac1db

Branches

Refs →

dotfiles-x1179ac1db

sbar

Author
krolyxon
Date
2022-08-26 12:23 +0530
Parent
9acd363
Commit
79ac1db3380d0cc89784f50823e1f4642d03e0ed

+77 −0

1 file changed

  1. A .local/bin/sbar +77 −0
A .local/bin/sbar View
@@ -0,0 +1,77 @@
1+#!/bin/env sh
2+
3+# INIT
4+printf "$$" > ~/.cache/pidofbar
5+sec=0
6+
7+# MODULES
8+update_cpu () {
9+ cpu=" $(grep -o "^[^ ]*" /proc/loadavg )"
10+}
11+
12+update_memory () {
13+ memory=" $(free -h | sed -n "2s/\([^ ]* *\)\{2\}\([^ ]*\).*/\2/p")"
14+}
15+
16+update_time () {
17+ time="$(date "+[ %a %d %b ] [ %I:%M %P ]")"
18+}
19+
20+update_weather () {
21+ weather=" $(curl -s "wttr.in?format=1" | awk '{printf $2}')"
22+}
23+
24+# update_bat () {
25+# # you might need to change the path depending on your device
26+# read -r bat_status </sys/class/power_supply/BAT1/status
27+# read -r bat_capacity </sys/class/power_supply/BAT1/capacity
28+# bat="$bat_status $bat_capacity%"
29+# }
30+
31+update_vol () {
32+ vol="$([ "$(pamixer --get-mute)" = "false" ] && printf ' ' || printf ' ')$(pamixer --get-volume)%"
33+}
34+
35+# For calcurse users, refer https://github.com/pystardust/automeet
36+#update_event () {
37+# event="$(calcurse -n | sed 1d | \
38+# sed -E "s_^ *\[(.*):(.*)\] ([^\t]*)\t?.*_[\1h \2m->\3]_")"
39+# [ "[]" = "$event" ] && event=""
40+#}
41+
42+
43+# modules that don't update on their own need to be run at the start for getting their initial value
44+update_vol
45+
46+display () {
47+ #printf "%s\n" " $event [$weather] [$memory $cpu] [$bat] [$backlight] [$vol] $time "
48+ xsetroot -name " [ $weather ] [ $memory $cpu ] [ $vol ] $time "
49+}
50+
51+# SIGNALLING
52+# trap "<function>;display" "RTMIN+n"
53+trap "update_vol;display" "RTMIN"
54+# trap "update_bat;display" "RTMIN+2"
55+# to update it from external commands
56+## kill -m "$(cat ~/.cache/pidofbar)"
57+# where m = 34 + n
58+
59+while true
60+do
61+ sleep 1 & wait && {
62+ # to update item ever n seconds with a offset of m
63+ ## [ $((sec % n)) -eq m ] && udpate_item
64+ [ $((sec % 5 )) -eq 0 ] && update_time # update time every 5 seconds
65+ [ $((sec % 5)) -eq 0 ] && update_cpu # update cpu every 15 seconds
66+ [ $((sec % 15)) -eq 0 ] && update_memory
67+ # [ $((sec % 60)) -eq 0 ] && update_bat
68+ [ $((sec % 3600)) -eq 2 ] && update_weather
69+ #[ $((sec % 300)) -eq 1 ] && update_event
70+
71+ # how often the display updates ( 5 seconds )
72+ [ $((sec % 5 )) -eq 0 ] && display
73+ sec=$((sec + 1))
74+ }
75+done
76+
77+