#!/bin/sh -e # lemonbar takes a formatted string as input # problem: i want to update different parts in different intervals # solution: setup fifo and put in information about what should be # updated. Create main loop that reads fifo, parses information, updates # what needs to be updated and fills in old information from previous # runs. feed the result to lemonbar. FONT="-zevv-peep-medium-r-normal--14-130-75-75-c-70-iso8859-15" # create fifo rm -f /tmp/lemonbar.fifo mkfifo /tmp/lemonbar.fifo # kill jobs when master script is killed set +o nohup # remove fifo when script is killed trap cleanup 1 2 3 13 15 cleanup() { printf "Cleaning up...\n" rm -f /tmp/lemonbar.fifo; } # update scripts update_desktop() { printf '%i\n' "$1"; } update_date() { date +"%Y-%m-%d %H:%M"; } update_temp() { sysctl -n hw.sensors.cpu0.temp0 | cut -d"." -f1; } update_load() { sysctl -n vm.loadavg | cut -d" " -f1; } update_bat() { apm -l; } update_vol() { mixerctl -n outputs.master; } update_wname() { WNAME=$(wname "$1" || printf "") if ! [ -z $WNAME ]; then printf '%s' "$WNAME" fi } # update whenever the desktop tag is changed xprop -spy -root -notype _NET_CURRENT_DESKTOP | \ while read desktop; do printf "%s\n" "$desktop" | awk '{ print $3 }'; done > /tmp/lemonbar.fifo & # update whenever the window focus is changed xprop -spy -root -notype _NET_ACTIVE_WINDOW | \ while read window; do printf "%s\n" "$window" | cut -d"#" -f2; done > /tmp/lemonbar.fifo & # update in 60 second intervals while true; do printf '%s\n' "DATE" printf '%s\n' "TEMP" printf '%s\n' "LOAD" printf '%s\n' "BAT" sleep 60 done > /tmp/lemonbar.fifo & # update once (will then be updated from outside) print "VOL" >> /tmp/lemonbar.fifo & # read fifo and create output for lemonbar while read line; do case $line in "DATE") _date=$(update_date); ;; "TEMP") _temp=$(update_temp); ;; "LOAD") _load=$(update_load); ;; "BAT") _bat=$(update_bat); ;; "VOL") _vol=$(update_vol); ;; "0x"*) _wname=$(update_wname "$line"); ;; *) _desktop=$(update_desktop "$line"); ;; esac printf "[%i] %s %%{r} VOL: %s | BAT: %i%% | LOAD: %s | CPU %i° | %s\n" "$_desktop" "$_wname" "$_vol" "$_bat" "$_load" "$_temp" "$_date" done < /tmp/lemonbar.fifo | lemonbar -d -f "$FONT" -B "#001800" -F "#CCCCCC" cleanup