Krolyxon
Commit 88bcaeb

Branches

Refs →

dotfiles-x11.localbinsbar

84 lines · 2.2 KB · Bourne Again Shell (bash)

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