Krolyxon
Commit 69905fb

Branches

Refs →

dotfiles-x11.localbinsbar

79 lines · 2.1 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}
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
31update_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
46display () {
47 #printf "%s\n" " $event [$memory $cpu] [$bat] [$backlight] [$vol] $time "
48 xsetroot -name "$music[ $vol ] [ $memory $cpu ] $time "
49}
50
51# SIGNALLING
52# trap "<function>;display" "RTMIN+n"
53trap "update_vol;display" "RTMIN"
54trap "update_music;display" "RTMIN+10"
55# trap "update_bat;display" "RTMIN+2"
56# to update it from external commands
57## kill -m "$(cat ~/.cache/pidofbar)"
58# where m = 34 + n
59
60while true
61do
62 sleep 1 & wait && {
63 # to update item ever n seconds with a offset of m
64 ## [ $((sec % n)) -eq m ] && udpate_item
65 [ $((sec % 5 )) -eq 0 ] && update_time # update time every 5 seconds
66 [ $((sec % 5 )) -eq 0 ] && update_vol # update vol every 5 seconds
67 [ $((sec % 5 )) -eq 0 ] && update_music # update music every 5 seconds
68 [ $((sec % 5)) -eq 0 ] && update_cpu # update cpu every 15 seconds
69 [ $((sec % 5)) -eq 0 ] && update_memory
70 # [ $((sec % 60)) -eq 0 ] && update_bat
71 #[ $((sec % 300)) -eq 1 ] && update_event
72
73 # how often the display updates ( 5 seconds )
74 [ $((sec % 5 )) -eq 0 ] && display
75 sec=$((sec + 1))
76 }
77done
78
79