From bb788dddf67c67d8ccd8f365187fea4d470a5d11 Mon Sep 17 00:00:00 2001 From: Manuel Palenzuela Date: Mon, 21 Oct 2019 20:09:02 +0100 Subject: [PATCH] Added volume module --- modules/archupdates | 1 + modules/battery | 29 +++++++++++++++++++---------- modules/bluetooth | 4 ++-- modules/volume | 21 +++++++++++++++++++++ 4 files changed, 43 insertions(+), 12 deletions(-) create mode 100755 modules/volume diff --git a/modules/archupdates b/modules/archupdates index edc7a41..ea44e2e 100755 --- a/modules/archupdates +++ b/modules/archupdates @@ -2,6 +2,7 @@ # Prints out the number of pacman updates (Arch Linux) # Requires an internet connection +# Depends on yay and checkupdates (pacman-contrib) PREFIX=' Updates:' diff --git a/modules/battery b/modules/battery index fa9d373..2802be9 100755 --- a/modules/battery +++ b/modules/battery @@ -1,31 +1,40 @@ #!/bin/bash +# Prints out battery percentage + +CHARGING_ICON='' +WARNING_ICON='' +BATTERY_FULL_ICON='' +BATTERY_2_ICON='' +BATTERY_3_ICON='' +BATTERY_4_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 "" + echo "$CHARGING_ICON" 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)%" ;; + 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 " $(cat $x)%" + echo "$BATTERY_4_ICON $(cat $x)%" else - echo "  $(cat $x)%" + echo "$WARNING_ICON $BATTERY_4_ICON $(cat $x)%" fi ;; [0-9]) if [ "$ac_adapter" == "Charging" ]; then - echo " $(cat $x)%" + echo "$BATTERY_4_ICON $(cat $x)%" else - echo "  $(cat $x)%" + echo "$WARNING_ICON $BATTERY_4_ICON $(cat $x)%" fi ;; esac done diff --git a/modules/bluetooth b/modules/bluetooth index 88a7a56..5dea2b0 100755 --- a/modules/bluetooth +++ b/modules/bluetooth @@ -11,10 +11,10 @@ get_bluetooth() if [ "$status" == "active" ] then - echo "" + echo "$BLUETOOTH_ON_ICON" else : - #echo "" + #echo "$BLUETOOTH_OFF_ICON" fi } diff --git a/modules/volume b/modules/volume new file mode 100755 index 0000000..27bb7dd --- /dev/null +++ b/modules/volume @@ -0,0 +1,21 @@ +#!/bin/bash + +# Prints out the volume percentage + +VOLUME_ON_ICON='' +VOLUME_MUTED_ICON='' + +get_volume(){ + active_sink=$(pacmd list-sinks | awk '/* index:/{print $3}') + curStatus=$(pacmd list-sinks | grep -A 15 "index: $active_sink$" | awk '/muted/{ print $2}') + volume=$(pacmd list-sinks | grep -A 15 "index: $active_sink$" | grep 'volume:' | grep -E -v 'base volume:' | awk -F : '{print $3}' | grep -o -P '.{0,3}%'| sed s/.$// | tr -d ' ') + + if [ "${curStatus}" = 'yes' ] + then + echo "$VOLUME_MUTED_ICON $volume%" + else + echo "$VOLUME_ON_ICON $volume%" + fi +} + +get_volume