Last active
August 6, 2021 02:39
-
-
Save ford-prefect/dee73257edfdb958ffd2710e5d05515b to your computer and use it in GitHub Desktop.
pactl port for polybar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
update_sink() { | |
sink=$(pactl info | sed -n '/^Default Sink:/ s/.*: //p') | |
} | |
volume_up() { | |
update_sink | |
pactl set-sink-volume "$sink" +1% | |
} | |
volume_down() { | |
update_sink | |
pactl set-sink-volume "$sink" -1% | |
} | |
volume_mute() { | |
update_sink | |
pactl set-sink-mute "$sink" toggle | |
} | |
volume_print() { | |
update_sink | |
active_port=$(pactl list sinks | sed -n "/Name: ${sink}/,/Name: /p" | grep Active) | |
if echo "$active_port" | grep -q speaker; then | |
icon="#1" | |
elif echo "$active_port" | grep -q headphones; then | |
icon="#2" | |
else | |
icon="#3" | |
fi | |
muted=$(pamixer --sink "$sink" --get-mute) | |
if [ "$muted" = true ]; then | |
echo "$icon --" | |
else | |
echo "$icon $(pamixer --sink "$sink" --get-volume)" | |
fi | |
} | |
listen() { | |
volume_print | |
pactl subscribe | while read -r event; do | |
if echo "$event" | grep -qv "Client"; then | |
volume_print | |
fi | |
done | |
} | |
case "$1" in | |
--up) | |
volume_up | |
;; | |
--down) | |
volume_down | |
;; | |
--mute) | |
volume_mute | |
;; | |
*) | |
listen | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment