Krolyxon
Commit 73a26ed

Branches

Refs →

dotfiles-x11.localbinsbar

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