diff options
author | Manuel Palenzuela <manuelpalenzuelamerino@gmail.com> | 2019-07-26 12:23:16 +0200 |
---|---|---|
committer | Manuel Palenzuela <manuelpalenzuelamerino@gmail.com> | 2019-07-26 12:23:16 +0200 |
commit | fbf746313f0a0ac5700499240eb0ba92441ef54e (patch) | |
tree | a1c1cc59d4399d67e1a705132457e36c24afb95d | |
parent | Added support for devel update checking (2/2) (diff) | |
download | dwm-fbf746313f0a0ac5700499240eb0ba92441ef54e.tar.gz dwm-fbf746313f0a0ac5700499240eb0ba92441ef54e.tar.bz2 dwm-fbf746313f0a0ac5700499240eb0ba92441ef54e.zip |
Refractored code
-rwxr-xr-x | scripts/dwm-status | 113 |
1 files changed, 63 insertions, 50 deletions
diff --git a/scripts/dwm-status b/scripts/dwm-status index 4fcfcaa..fef0d4b 100755 --- a/scripts/dwm-status +++ b/scripts/dwm-status @@ -105,24 +105,7 @@ bluetooth() { fi } -# Here is the (big) function that outputs the appearance of the statusbar. It -# can really be broken down into many submodules which I've commented and -# explained. -status() { \ - - tor - - # Directs to the path of the weather script. - echo $(python $( cd "$(dirname "$0")" ; pwd -P )/weather.py) - # echo "$delim" (done in the weather script) - - updates - - # Show unread mail - command -v neomutt >/dev/null 2>&1 && - du -a ~/Mail/INBOX/new/* 2>/dev/null | wc -l | sed 's/^/: /' && - echo "$delim" - +volume(){ # Get the volume of ALSA's master volume output. Show an icon if or # not muted. active_sink=$(pacmd list-sinks | awk '/* index:/{print $3}') @@ -136,13 +119,9 @@ status() { \ fi echo "$delim" +} - bluetooth - - echo "$delim" - - wireless - +temperature(){ CPU_T=$(< /sys/devices/platform/coretemp.0/hwmon/hwmon0/temp2_input) CPU_TEMP=$(expr "$CPU_T" / 1000) @@ -154,35 +133,69 @@ status() { \ echo " $CPU_TEMP°C" fi echo "$delim" +} - # Will show all batteries with approximate icon for remaining power. - ac_adapter=$(cat /sys/class/power_supply/BAT?/status) - if [ "$ac_adapter" == "Charging" ]; then - echo "" - else - : +battery(){ + if [ -d /sys/class/power_supply/BAT? ]; then + + ac_adapter=$(cat /sys/class/power_supply/BAT?/status) + if [ "$ac_adapter" == "Charging" ]; then + echo "" + fi + + # Will show all batteries with approximate icon for remaining power. + for x in /sys/class/power_supply/BAT?/capacity; + do + case "$(cat $x)" in + 100) echo "" ;; + 9[0-9]) echo " $(cat $x)%" ;; + 8[0-9]|7[0-9]) echo " $(cat $x)%" ;; + 6[0-9]|5[0-9]) echo " $(cat $x)%" ;; + 4[0-9]|3[0-9]) echo " $(cat $x)%" ;; + 2[0-9]|1[0-9]) if [ "$ac_adapter" == "Charging" ]; then + echo " $(cat $x)%" + else + echo " $(cat $x)%" + fi ;; + [0-9]) if [ "$ac_adapter" == "Charging" ]; then + echo " $(cat $x)%" + else + echo " $(cat $x)%" + fi ;; + esac + done && echo "$delim" fi +} + +# Here is the (big) function that outputs the appearance of the statusbar. It +# can really be broken down into many submodules which I've commented and +# explained. +status() { \ + + tor + + # Directs to the path of the weather script. + echo $(python $( cd "$(dirname "$0")" ; pwd -P )/weather.py) + # echo "$delim" (done in the weather script) + + updates + + # Show unread mail + command -v neomutt >/dev/null 2>&1 && + du -a ~/Mail/INBOX/new/* 2>/dev/null | wc -l | sed 's/^/: /' && + echo "$delim" + + volume + + bluetooth + + echo "$delim" + + wireless + + temperature - for x in /sys/class/power_supply/BAT?/capacity; - do - case "$(cat $x)" in - 100) echo "" ;; - 9[0-9]) echo " $(cat $x)%" ;; - 8[0-9]|7[0-9]) echo " $(cat $x)%" ;; - 6[0-9]|5[0-9]) echo " $(cat $x)%" ;; - 4[0-9]|3[0-9]) echo " $(cat $x)%" ;; - 2[0-9]|1[0-9]) if [ "$ac_adapter" == "Charging" ]; then - echo " $(cat $x)%" - else - echo " $(cat $x)%" - fi ;; - [0-9]) if [ "$ac_adapter" == "Charging" ]; then - echo " $(cat $x)%" - else - echo " $(cat $x)%" - fi ;; - esac - done && echo "$delim" + battery # Date and time. FORMAT CORRECT NO PM echo " $(date '+%d-%m-%y (%a) | %H:%M')" |