Re-add different volume icons, and make the source variable more robust

This commit is contained in:
krisdoodle45 2021-09-28 21:10:18 +02:00 committed by GitHub
parent 4192971e8b
commit 4818f21e52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,23 +1,37 @@
#!/bin/sh #!/bin/sh
if [ "$(pamixer --get-mute)" = "true" ]; then # Prints the current volume or 🔇 if muted. Also shows 🎙️ if there's an unmuted microphone.
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
case $BLOCK_BUTTON in case $BLOCK_BUTTON in
1) setsid -f "$TERMINAL" -e pulsemixer ;; 1) setsid -f "$TERMINAL" -e pulsemixer ;;
2) pamixer -t ;; 2) pamixer -t ;;
4) pamixer --allow-boost -i 1 ;; 4) pamixer --allow-boost -i 1 ;;
5) pamixer --allow-boost -d 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. - Middle click to mute.
- Scroll to change." ;; - Scroll to change." ;;
6) "$TERMINAL" -e "$EDITOR" "$0" ;; 6) "$TERMINAL" -e "$EDITOR" "$0" ;;
esac 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"