OSDN Git Service

fix status bar
authorpaperbenni <paperbenni@gmail.com>
Fri, 20 Mar 2020 16:17:25 +0000 (17:17 +0100)
committerpaperbenni <paperbenni@gmail.com>
Fri, 20 Mar 2020 16:17:25 +0000 (17:17 +0100)
status.sh

index 3ae6c90..cc9d6b4 100755 (executable)
--- a/status.sh
+++ b/status.sh
@@ -7,37 +7,43 @@
 INTERNET="X"
 date=""
 
-
 RED='#fc4138'
 GREEN='#73d216'
 
-# append item with brackets
+istat() {
+    echo "$2" >/tmp/instantos/status/"$1"
+}
+
 addstatus() {
-    date="${date}| $@"
+    date="${date} [$@]"
 }
 
+mkdir -p /tmp/instantos/status
+
 # update different parts with different frequency
 
 # 1m loop
 while :; do
     if ping -q -c 1 -W 1 8.8.8.8; then
-        INTERNET="i"
+        INTERNET="^c$GREEN^i^d^"
     else
         INTERNET="^c$RED^X^d^"
     fi
+    istat INTERNET "$INTERNET"
 
     # battery indicator on laptop
     if [ -n "$ISLAPTOP" ]; then
         TMPBAT=$(acpi)
         if [[ $TMPBAT =~ "Charging" ]]; then
-            BATTERY="^c$GREEN^B"$(egrep -o '[0-9]*%' <<<"$TMPBAT")"^d^"
+            BATTERY="^c$GREEN^"$(egrep -o '[0-9]*%' <<<"$TMPBAT")"^d^"
         else
-            BATTERY="B"$(egrep -o '[0-9]*%' <<<"$TMPBAT")
+            BATTERY=$(egrep -o '[0-9]*%' <<<"$TMPBAT")
             # make indicator red on low battery
             if [ $(grep '[0-9]*' <<<$BATTERY) -lt 10 ]; then
                 BATTERY="^c$RED^$BATTERY^d^"
             fi
         fi
+        istat BATTERY "B$BATTERY"
     fi
     sleep 1m
 
@@ -57,6 +63,7 @@ while :; do
             echo "system is up to date"
             unset UPDATES
         fi
+        istat UPDATES "U$UPDATES"
     fi
 done &
 
@@ -64,22 +71,21 @@ sleep 2
 
 # 10 sec loop
 while :; do
-
     # option to disable status text and check for enabling it again
     if [ -e ~/.instantsilent ]; then
         sleep 1m
         continue
     fi
 
+    for i in /tmp/instantos/status/*; do
+        date="${date} [$(cat $i)]"
+    done
+
     # date time
-    addstatus "$(date +'%d-%m,%H:%M')"
+    addstatus "$(date +'%d-%m|%H:%M')"
     # volume
     addstatus "A$(amixer get Master | egrep -o '[0-9]{1,3}%' | head -1)"
 
-    # 60 sec info
-    [ -n "$ISLAPTOP" ] && addstatus "B$BATTERY"
-    addstatus "$INTERNET"
-    [ -n "$UPDATES" ] && addstatus "U$UPDATES"
     # add 11 px spacing
     xsetroot -name "^f11^$date"
     date=""