From 604fe4aac5a4d0ed176156af338b0f3973d1c63c Mon Sep 17 00:00:00 2001 From: Valentin Gehrke Date: Thu, 11 Jun 2015 11:52:30 +0200 Subject: [PATCH] Only 1 format string necessary --- scripts/bar.sh | 8 ++++---- scripts/barformatter.py | 17 +++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/scripts/bar.sh b/scripts/bar.sh index 2da07d7..75de964 100755 --- a/scripts/bar.sh +++ b/scripts/bar.sh @@ -2,8 +2,7 @@ FIFO="/tmp/bar.fifo" -FORMAT_LEFT=" %(music)s %(services)s %(diskspace)s" -FORMAT_RIGHT="%(updates)s %(wifi)s %(battery)s %(clock)s " +FORMAT=" %(music)s %(services)s %(diskspace)s %%{c} %(debug)s %%{r} %(updates)s %(wifi)s %(battery)s %(clock)s " icon_color="#A0A57E" icon() { echo -n "%{F$icon_color}"; printf '%b' "\ue$1"; echo -n "%{F-}"; } @@ -133,7 +132,7 @@ run_handler() { cd $(dirname $0) #Trap magic -trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT +trap "trap - SIGTERM && kill -9 -- -$$" SIGINT SIGTERM EXIT #Fifo [ -e "$FIFO" ] && rm -f $FIFO @@ -148,5 +147,6 @@ diskspace & wifi & updates & -( 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 +( while true; do cat $FIFO; done ) | python ./barformatter.py "$FORMAT" | lemonbar -g 1366x15 -f "Stlarch:size=6:style=regular" -f "Terminus:size=8" -B "#88000000" | run_handler +exit 0 diff --git a/scripts/barformatter.py b/scripts/barformatter.py index 51e3cee..e37eebc 100755 --- a/scripts/barformatter.py +++ b/scripts/barformatter.py @@ -8,17 +8,18 @@ class DefaultDict(dict): def __getitem__(self, key): return self.get(key, self.default) -if len(argv) <= 2: - print("%s " % argv[0]) +if len(argv) <= 1: + print("%s " % argv[0]) exit(1) -format_left = argv[1] -format_right = argv[2] +format_str = argv[1] cache = DefaultDict("") -_format = lambda: '%{l}' + (format_left % cache) + '%{r}' + (format_right % cache) - while True: - print(_format()) - tag,content = input().rstrip('\n').split(' ',1) + print(format_str % cache) + data = input().rstrip('\n').split(' ',1) + if len(data) < 2: + tag,content = data[0],"" + else: + tag,content = data cache[tag] = content