From b6c66204fd96231cea02fcf98dbb376a9e1bed07 Mon Sep 17 00:00:00 2001 From: "Archie Hilton (thytom)" Date: Thu, 24 Oct 2019 20:33:19 +0100 Subject: [PATCH 1/4] Add condition to prevent module being run multiple times. Parallelisation means that some modules are going to be slower than the delay time, and therefore will pile up. --- bar.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bar.sh b/bar.sh index f9866f4..63bff6f 100755 --- a/bar.sh +++ b/bar.sh @@ -15,7 +15,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . - MODULES_DIR="/usr/share/dwmbar/modules/" OUTPUT_CACHE="/home/$USER/.config/dwmbar/.cache/" @@ -67,8 +66,9 @@ run() { get_internet for module in $MODULES; do - if [[ $INTERNET -eq 0 ]]; then - run_module $module + pgrep $module &> /dev/null + if [[ $INTERNET -eq 0 ]] && [[ $? -eq 1 ]]; then + run_module $module & else [[ $ONLINE_MODULES != *"$module"* ]] && run_module $module fi From 7eba91d0383d44d5520485cbb64158142866b677 Mon Sep 17 00:00:00 2001 From: "Archie Hilton (thytom)" Date: Fri, 25 Oct 2019 01:24:02 +0100 Subject: [PATCH 2/4] Re-wrote battery script to be faster and more efficient. --- modules/battery | 53 ++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/modules/battery b/modules/battery index 2802be9..4ad12ff 100755 --- a/modules/battery +++ b/modules/battery @@ -9,36 +9,35 @@ BATTERY_2_ICON='' BATTERY_3_ICON='' BATTERY_4_ICON='' +FULL_AT=98 + +BAT_ICON="" +ICON="" + get_battery() { - if [ -d /sys/class/power_supply/BAT? ]; then - ac_adapter=$(cat /sys/class/power_supply/BAT?/status) - if [ "$ac_adapter" == "Charging" ]; then - echo "$CHARGING_ICON" - fi + # The vast majority of people only use one battery. - # 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 "$BATTERY_FULL_ICON" ;; - 9[0-9]) echo "$BATTERY_FULL_ICON $(cat $x)%" ;; - 8[0-9]|7[0-9]) echo "$BATTERY_2_ICON $(cat $x)%" ;; - 6[0-9]|5[0-9]) echo "$BATTERY_3_ICON $(cat $x)%" ;; - 4[0-9]|3[0-9]) echo "$BATTERY_4_ICON $(cat $x)%" ;; - 2[0-9]|1[0-9]) if [ "$ac_adapter" == "Charging" ]; then - echo "$BATTERY_4_ICON $(cat $x)%" - else - echo "$WARNING_ICON $BATTERY_4_ICON $(cat $x)%" - fi ;; - [0-9]) if [ "$ac_adapter" == "Charging" ]; then - echo "$BATTERY_4_ICON $(cat $x)%" - else - echo "$WARNING_ICON $BATTERY_4_ICON $(cat $x)%" - fi ;; - esac - done - fi + if [ -d /sys/class/power_supply/BAT0 ]; then + capacity=$(cat /sys/class/power_supply/BAT0/capacity) + charging=$(cat /sys/class/power_supply/BAT0/status) + if [[ "$charging" == "Charging" ]]; then + ICON="$CHARGING_ICON" + elif [[ $capacity -le 25 ]]; then + ICON="$WARNING_ICON" + fi + + if [[ $capacity -ge $FULL_AT ]]; then + BAT_ICON=$BATTERY_FULL_ICON + elif [[ $capacity -le 25 ]]; then + BAT_ICON=$BATTERY_4_ICON + elif [[ $capacity -le 50 ]]; then + BAT_ICON=$BATTERY_3_ICON + elif [[ $capacity -le $FULL_AT ]]; then + BAT_ICON=$BATTERY_2_ICON + fi + fi + echo "$ICON $BAT_ICON $capacity%" } get_battery From 8df3820882a8c470190f209888cf2f04c45d5193 Mon Sep 17 00:00:00 2001 From: "Archie Hilton (thytom)" Date: Fri, 25 Oct 2019 01:27:35 +0100 Subject: [PATCH 3/4] Fix percentage text inside battery icon. --- modules/battery | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/battery b/modules/battery index 4ad12ff..901a66e 100755 --- a/modules/battery +++ b/modules/battery @@ -2,12 +2,12 @@ # Prints out battery percentage -CHARGING_ICON='' -WARNING_ICON='' -BATTERY_FULL_ICON='' -BATTERY_2_ICON='' -BATTERY_3_ICON='' -BATTERY_4_ICON='' +CHARGING_ICON=' ' +WARNING_ICON=' ' +BATTERY_FULL_ICON=' ' +BATTERY_2_ICON=' ' +BATTERY_3_ICON=' ' +BATTERY_4_ICON=' ' FULL_AT=98 @@ -37,7 +37,7 @@ get_battery() BAT_ICON=$BATTERY_2_ICON fi fi - echo "$ICON $BAT_ICON $capacity%" + echo "$ICON $BAT_ICON $capacity%" } get_battery From 304d4863d1034ea6fb0d5850fd4a3de6c52693fe Mon Sep 17 00:00:00 2001 From: "Archie Hilton (thytom)" Date: Fri, 25 Oct 2019 11:42:13 +0100 Subject: [PATCH 4/4] Quoted all variables, to avoid whitespace truncation. --- bar.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bar.sh b/bar.sh index 63bff6f..1055177 100755 --- a/bar.sh +++ b/bar.sh @@ -40,8 +40,8 @@ get_bar() { for module in $MODULES; do if [[ $INTERNET -eq 0 ]] || [[ $ONLINE_MODULES != *"$module"* ]];then - module_out=$(cat $OUTPUT_CACHE$module | sed 's/\.$//g') - bar=$bar$module_out + module_out="$(cat $OUTPUT_CACHE$module | sed 's/\.$//g')" + bar="$bar$module_out" fi done # Uncomment to remove last separator @@ -59,7 +59,7 @@ run_module() fi [[ ! "$out" = "" ]] && [[ ! "$module" = "NULL" ]] && out="$out$SEPARATOR." - echo $out > "$OUTPUT_CACHE$module" + echo "$out" > "$OUTPUT_CACHE$module" } run()