x-widgets - scripts - various script and utils
HTML git clone git://z3bra.org/scripts
DIR Log
DIR Files
DIR Refs
---
x-widgets (5155B)
---
1 #!/bin/sh
2
3 bg=${BG_COLOR:-#00000000}
4 fg=${FG_COLOR:-#ff000000}
5 fn1='Monospace:size=12:antialias=true:autohint=true'
6 fn2='Monospace:weight=bold:size=12:antialias=true:autohint=true'
7
8 usage() {
9 echo "usage: $(basename $0) [-hr] [-xy pos] [-fb color]" >&2
10 }
11
12 reload() {
13 pkill lemonbar
14 exec $0
15 }
16
17 clock() {
18 while pgrep widgets >/dev/null; do
19 printf '%%{T2}%s %%{T-}%s\n' "$(LANG=fr_FR.UTF-8 date '+%a %d')" "$(date +%H:%M)"
20 sleep 60
21 done
22 }
23
24 palovpn() {
25 while pgrep widgets >/dev/null; do
26 vpn="$(</dev/null timeout 5s globalprotect show --status | tr A-Z a-z | grep -Eo 'status: .*' | cut -d' ' -f2)"
27 printf '%%{T2}vpn %%{T-}%s\n' ${vpn:-down}
28 sleep 10
29 done
30 }
31
32 ifname() {
33 if=$(ip route | grep '^default' | head -n1 | cut -d ' ' -f5)
34 case $if in
35 bond0) cat /sys/class/net/$if/bonding/active_slave ;;
36 *) printf '%s\n' "$if"
37 esac
38 }
39
40 network() {
41 while pgrep widgets >/dev/null; do
42 if=$(ifname)
43 case $if in
44 en*) printf '%%{T2}wired %%{T-}%s\n' $if ;;
45 wl*)
46 rfkill="$(LC_ALL=C rfkill -r | grep wlan | cut -d ' ' -f 4)"
47 if [ "$rfkill" = "blocked" ]; then
48 ssid="BLOCKED"
49 else
50 ssid=$(iw dev $if link|sed -n 's/.*SSID: //p')
51 fi
52 printf '%%{T2}ssid %%{T-}%s\n' "${ssid:--}"
53 ;;
54 *) printf '%%{T2}network %%{T-}down\n' ;;
55 esac
56 sleep 1
57 done
58 }
59
60 # click on volume to toggle it
61 # mouse scroll on volume to increase/decrease
62 # require scripts named "speakers" and "microphone" to be in $PATH to work
63 sound() {
64 dev=$1
65 while pgrep widgets >/dev/null; do
66 printf '%%{T2}%s %%{T-}%%{+u}' $dev
67 printf '%%{A:%s toggle:}' $dev
68 printf '%%{A4:%s +5%%:}' $dev
69 printf '%%{A5:%s -5%%:}' $dev
70 printf ' %s %%{A}%%{A}%%{A}%%{-u}\n' "$($dev)"
71 sleep 1
72 done
73 }
74
75 battery() {
76 while pgrep widgets >/dev/null; do
77 lvl="$(cat /sys/class/power_supply/$1/capacity)"
78 ac="$(cat /sys/class/power_supply/$1/status)"
79 case $ac in
80 Charging) ac='+' ;;
81 *) ac='' ;;
82 esac
83 printf '%%{T2}juice %%{T-}%d%%%c\n' "$lvl" "$ac"
84 sleep 10
85 done
86 }
87
88 cpufreq() {
89 while pgrep widgets >/dev/null; do
90 mode=$(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor|uniq)
91 freq=$(</proc/cpuinfo awk 'BEGIN{print "3k"} /MHz/{print $4} END{print "+++++++++++++++++++++ 1000000* 21/ p"}'|dc)
92 printf '%%{T2}cpu %%{T-}%sHz (%%{+u}' "$(SCALE=1 human ${freq})"
93 case $mode in
94 powersave) name="chill"; gov="performance";;
95 performance) name="boost"; gov="powersave";;
96 *) name="idk";;
97 esac
98 printf '%%{A:doas cpupower -c 0-21 frequency-set -g %s:}%s%%{A}%%{-u})\n' "$gov" "$name"
99 sleep 2
100 done
101 }
102
103 desktop_groups() {
104 while pgrep widgets >/dev/null; do
105 groups="$(gm -l | sort | sed -r 's,GM_([0-9]+),\1,' | tr '\n' ' ')"
106 if [ -n "$groups" ]; then
107 printf '%%{T2}groups %%{T-}%s\n' "$groups"
108 else
109 printf '%%{T2}groups %%{T-}none\n'
110 fi
111 sleep 2
112 done
113 }
114
115 meetings() {
116 n=$(remind -naa $HOME/.reminders | grep ^$(date +%Y/%m/%d) | wc -l)
117 [ "$n" -eq 0 ] && return
118 [ "$n" -gt 1 ] && c=s
119
120 printf '(%%{T2}%%{A:meetings:}%d event%s%%{A}%%{T-})\n' "$n" "$c"
121 }
122
123 time_tracker() {
124 while pgrep widgets >/dev/null; do
125 if ! flock -n $HOME/.cache/tt/.lock true; then
126 msg="$(awk -F '[][]' '{print $1 $2}' $HOME/.cache/tt/current)"
127 printf '%%{T2}kpi%%{T-} %s\n' "$msg"
128 else
129 printf '%%{T2}kpi %%{T-} untracked\n'
130 fi
131 sleep 5
132 done
133 }
134
135 mailbox() {
136 mh=$HOME/lib/mail
137 box=${1:-inbox}
138 while pgrep widgets >/dev/null; do
139 total=$(mlist $mh/$box | wc -l)
140 unread=$(mlist -s $mh/$box | wc -l)
141 printf '%%{T2}%s %%{T-}%d/%d %s\n' $box $unread $total "$(meetings)"
142 sleep 5
143 done
144 }
145
146 traffic() {
147 if=${1:-$(ifname)}
148 sbm -t -i $if | while read rx tx rxpps txpps; do
149 printf '%%{T2}traffic ↓↑ %%{T-}%s/%s %s\n' $(human $rx) $(human $tx)
150 done
151 }
152
153 x=32
154 y=28
155
156 while getopts "hx:y:f:b:" OPT; do
157 case $OPT in
158 r) reload; exit 0;;
159 x) x=$OPTARG;;
160 y) y=$OPTARG;;
161 f) fg=$OPTARG;;
162 b) bg=$OPTARG;;
163 h) usage; exit 0;;
164 *) usage; exit 1;;
165 esac
166 done
167
168 y=$((y + 28)); battery BAT0 | lemonbar -db -U "$fg" -B "$bg" -F "$fg" -f "$fn1" -f "$fn2" -g 300x28+$x+$y &
169 y=$((y + 28)); sound speakers | lemonbar -db -U "$fg" -B "$bg" -F "$fg" -f "$fn1" -f "$fn2" -g 300x28+$x+$y | sh &
170 y=$((y + 28)); sound microphone | lemonbar -db -U "$fg" -B "$bg" -F "$fg" -f "$fn1" -f "$fn2" -g 300x28+$x+$y | sh &
171 y=$((y + 28)); cpufreq | lemonbar -db -U "$fg" -B "$bg" -F "$fg" -f "$fn1" -f "$fn2" -g 300x28+$x+$y | sh &
172 #y=$((y + 28)); traffic $(ifname)| lemonbar -db -U "$fg" -B "$bg" -F "$fg" -f "$fn1" -f "$fn2" -g 300x28+$x+$y &
173 #y=$((y + 28)); desktop_groups | lemonbar -db -U "$fg" -B "$bg" -F "$fg" -f "$fn1" -f "$fn2" -g 300x28+$x+$y &
174 y=$((y + 28)); palovpn gpd0 | lemonbar -db -U "$fg" -B "$bg" -F "$fg" -f "$fn1" -f "$fn2" -g 300x28+$x+$y &
175 y=$((y + 28)); time_tracker | lemonbar -db -U "$fg" -B "$bg" -F "$fg" -f "$fn1" -f "$fn2" -g 300x28+$x+$y &
176 y=$((y + 28)); network | lemonbar -db -U "$fg" -B "$bg" -F "$fg" -f "$fn1" -f "$fn2" -g 300x28+$x+$y &
177 y=$((y + 28)); mailbox inbox | lemonbar -db -U "$fg" -B "$bg" -F "$fg" -f "$fn1" -f "$fn2" -g 300x28+$x+$y | sh &
178 y=$((y + 28)); clock | lemonbar -db -U "$fg" -B "$bg" -F "$fg" -f "$fn1" -f "$fn2" -g 300x28+$x+$y &
179
180 wait