multiprocess bar

This commit is contained in:
madmaurice 2015-06-09 22:41:53 +02:00
parent 05a3e848a2
commit 5fb95bcab3
2 changed files with 50 additions and 6 deletions

View file

@ -1,6 +1,9 @@
#!/bin/bash #!/bin/bash
cd $(dirname $0) FIFO="/tmp/bar.fifo"
FORMAT_LEFT="%(music)s %(services)s %(diskspace)s"
FORMAT_RIGHT="%(wifi)s %(battery)s %(clock)s "
icon_color="#A0A57E" icon_color="#A0A57E"
icon() { echo -n "%{F$icon_color}"; printf '%b' "\ue$1"; echo -n "%{F-}"; } icon() { echo -n "%{F$icon_color}"; printf '%b' "\ue$1"; echo -n "%{F-}"; }
@ -74,7 +77,7 @@ battery() {
info="%{F$color_battery_low}$level%%{F-}" info="%{F$color_battery_low}$level%%{F-}"
fi fi
echo -n "%{A:I "battery 1061":}$icon $info%{A}" echo -n "%{A:I 'battery 1061':}$icon $info%{A}"
} }
clock() { clock() {
@ -98,9 +101,26 @@ run_handler() {
done done
} }
run_worker() {
SLEEP=$1
TAG=$2
COMMAND=$3
( while true; do
echo -n "$TAG "
$COMMAND
echo
sleep $SLEEP
done > $FIFO ) &
}
while true; do cd $(dirname $0)
echo "%{l} $(music) $(services) $(diskspace)%{r}$(updates) $(wifi) $(battery) $(clock) "
sleep 1 [ -e "$FIFO" ] && rm -f $FIFO
done | lemonbar -g 1366x15 -f "Stlarch:size=6:style=regular" -f "Terminus:size=8" -B "#88000000" | run_handler mkfifo $FIFO
run_worker 1 clock clock
run_worker 5 battery battery
( while true; do cat $FIFO; done ) | python ./barformatter.py "$FORMAT_LEFT" "$FORMAT_RIGHT" # | lemonbar -g 1366x15 -f "Stlarch:size=6:style=regular" -f "Terminus:size=8" -B "#88000000" | run_handler

24
scripts/barformatter.py Executable file
View file

@ -0,0 +1,24 @@
from sys import argv, exit
class DefaultDict(dict):
def __init__(self,default):
super(DefaultDict, self).__init__()
self.default = default
def __getitem__(self, key):
return self.get(key, self.default)
if len(argv) <= 2:
print("%s <format_left> <format_right>" % argv[0])
exit(1)
format_left = argv[1]
format_right = argv[2]
cache = DefaultDict("")
_format = lambda: '%{l}' + (format_left % cache) + '%{r}' + (format_right % cache)
while True:
print(_format())
tag,content = input().rstrip('\n').split(' ',1)
cache[tag] = content