Skip to content

Commit

Permalink
added calcurse module
Browse files Browse the repository at this point in the history
  • Loading branch information
pystardust committed Feb 18, 2021
1 parent 9e547bb commit e4617f1
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions sbar
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/bin/sh
exec 2>&1
#!/bin/env sh

# INIT
printf "$$" > ~/.cache/pidofbar
sec=0

# MODULES
update_cpu () {
cpu="$( grep -o "^[^ ]*" /proc/loadavg )"
cpu="$(grep -o "^[^ ]*" /proc/loadavg )"
}

update_memory () {
Expand All @@ -21,54 +22,62 @@ update_weather () {
}

update_bat () {
# you might need to change the path depending on your device
read -r bat_status </sys/class/power_supply/BAT1/status
read -r bat_capacity </sys/class/power_supply/BAT1/capacity
bat="$bat_status $bat_capacity%"
}

# modules that don't update on their own
# they are also run at the start for getting the initial value
update_vol () {
vol="$([ "$(pamixer --get-mute)" = "false" ] && printf '🔊' || printf '🔇')$(pamixer --get-volume)%"
}
update_vol

update_backlight () {
# you might need to change the path depending on your device
read -r actual_brightness </sys/class/backlight/intel_backlight/actual_brightness
read -r max_brightness </sys/class/backlight/intel_backlight/max_brightness
backlight="$((actual_brightness*100/max_brightness))%"
}

# For calcurse users, refer https://github.com/pystardust/automeet
#update_event () {
# event="$(calcurse -n | sed 1d | \
# sed -E "s_^ *\[(.*):(.*)\] ([^\t]*)\t?.*_[\1h \2m->\3]_")"
# [ "[]" = "$event" ] && event=""
#}


# modules that don't update on their own need to be run at the start for getting their initial value
update_vol
update_backlight

display () {
#printf "%s\n" "$event [$weather] [$memory $cpu] [$bat] [$backlight] [$mic$vol] $time "
#printf "%s\n" " $event [$weather] [$memory $cpu] [$bat] [$backlight] [$vol] $time "
xsetroot -name " [$weather] [$memory $cpu] [$bat] [$backlight] [$vol] $time "
}


# Signals for each module to update. RTMIN is 34
## trap "<function to update>;display" "RTMIN+n"
# SIGNALLING
# trap "<function>;display" "RTMIN+n"
trap "update_vol;display" "RTMIN"
trap "update_backlight;display" "RTMIN+1"
trap "update_bat;display" "RTMIN+2"
# to update it from external commands
## kill -m "$(cat ~/.cache/pidofbar)"
# where m = 34 + n
trap "update_vol;display" "RTMIN"
trap "update_backlight;display" "RTMIN+1"
trap "update_bat;display" "RTMIN+2"

while true
do
sleep 1 & wait && {
# update interval of module in seconds
## [ $((sec % n)) -eq m ] && udpate_item
# to update item ever n seconds with a offset of m
## [ $((sec % n)) -eq m ] && udpate_item
[ $((sec % 5 )) -eq 0 ] && update_time # update time every 5 seconds
[ $((sec % 15)) -eq 0 ] && update_cpu # update cpu every 15 seconds
[ $((sec % 15)) -eq 0 ] && update_memory
[ $((sec % 60 )) -eq 0 ] && update_bat
# update offset so that all of them don't update on the same second
[ $((sec % 3600 )) -eq 2 ] && update_weather # updates weather every hour with a 2 second offset
[ $((sec % 60)) -eq 0 ] && update_bat
[ $((sec % 3600)) -eq 2 ] && update_weather
#[ $((sec % 300)) -eq 1 ] && update_event

# how often the display updates ( 5 secconds )
# how often the display updates ( 5 seconds )
[ $((sec % 5 )) -eq 0 ] && display
sec=$((sec + 1))
}
Expand Down

0 comments on commit e4617f1

Please sign in to comment.