From 4818f21e52f9a4a4bb48923b7f5c251d44fbdb49 Mon Sep 17 00:00:00 2001 From: krisdoodle45 <86745210+krisdoodle45@users.noreply.github.com> Date: Tue, 28 Sep 2021 21:10:18 +0200 Subject: [PATCH] Re-add different volume icons, and make the source variable more robust --- .local/bin/statusbar/sb-volume | 36 +++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/.local/bin/statusbar/sb-volume b/.local/bin/statusbar/sb-volume index e4dd4984..7000bdf5 100755 --- a/.local/bin/statusbar/sb-volume +++ b/.local/bin/statusbar/sb-volume @@ -1,23 +1,37 @@ #!/bin/sh -if [ "$(pamixer --get-mute)" = "true" ]; then - printf "🔇 $(pamixer --get-volume)%%" -else - printf "🔊 $(pamixer --get-volume)%%" -fi - -source="$(pamixer --list-sources | awk '!/Built/{ if (NR==2) {print $1} }')" -if [ "$(pamixer --source $source --get-mute)" = "false" ]; then - printf " 🎙️\n" -fi +# Prints the current volume or 🔇 if muted. Also shows 🎙️ if there's an unmuted microphone. case $BLOCK_BUTTON in 1) setsid -f "$TERMINAL" -e pulsemixer ;; 2) pamixer -t ;; 4) pamixer --allow-boost -i 1 ;; 5) pamixer --allow-boost -d 1 ;; - 3) notify-send "📢 Volume module" "\- Shows volume 🔊, 🔇 if muted. + 3) notify-send "📢 Volume module" "\- Shows volume 🔊, 🔇 if muted. Also shows 🎙️ if there's an unmuted microphone. - Middle click to mute. - Scroll to change." ;; 6) "$TERMINAL" -e "$EDITOR" "$0" ;; esac + +if [ $(pamixer --get-mute) = true ]; then + icon="🔇" +else + vol="$(pamixer --get-volume)" + + if [ "$vol" -gt "70" ]; then + icon="🔊" + elif [ "$vol" -lt "30" ]; then + icon="🔈" + else + icon="🔉" + fi +fi + +# If the first source that is not a monitor is unmuted, print 🎙️ +source="$(pamixer --list-sources | awk '!/Built/{ cnt++ ; if (cnt == 2) print $1 }')" +[ "$(pamixer --source $source --get-mute)" = "false" ] && mic="🎙️" + +# If the audio is not muted, add % to vol +[ ! -z "$vol" ] && vol="$vol%" +# Prints the info +printf "%s%s %s\n" "$icon" "$vol" "$mic"