From 5fb95bcab3cff6d83439195e6b422e8a1ef7edb4 Mon Sep 17 00:00:00 2001 From: Valentin Gehrke Date: Tue, 9 Jun 2015 22:41:53 +0200 Subject: [PATCH] multiprocess bar --- scripts/bar.sh | 32 ++++++++++++++++++++++++++------ scripts/barformatter.py | 24 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 6 deletions(-) create mode 100755 scripts/barformatter.py diff --git a/scripts/bar.sh b/scripts/bar.sh index c86e63b..db82110 100755 --- a/scripts/bar.sh +++ b/scripts/bar.sh @@ -1,6 +1,9 @@ #!/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() { echo -n "%{F$icon_color}"; printf '%b' "\ue$1"; echo -n "%{F-}"; } @@ -74,7 +77,7 @@ battery() { info="%{F$color_battery_low}$level%%{F-}" fi - echo -n "%{A:I "battery 1061":}$icon $info%{A}" + echo -n "%{A:I 'battery 1061':}$icon $info%{A}" } clock() { @@ -98,9 +101,26 @@ run_handler() { done } +run_worker() { + SLEEP=$1 + TAG=$2 + COMMAND=$3 + ( while true; do + echo -n "$TAG " + $COMMAND + echo + sleep $SLEEP + done > $FIFO ) & +} -while true; do - echo "%{l} $(music) $(services) $(diskspace)%{r}$(updates) $(wifi) $(battery) $(clock) " - sleep 1 -done | lemonbar -g 1366x15 -f "Stlarch:size=6:style=regular" -f "Terminus:size=8" -B "#88000000" | run_handler +cd $(dirname $0) + +[ -e "$FIFO" ] && rm -f $FIFO +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 diff --git a/scripts/barformatter.py b/scripts/barformatter.py new file mode 100755 index 0000000..51e3cee --- /dev/null +++ b/scripts/barformatter.py @@ -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 " % 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