dotfiles/.local/bin/vol

36 lines
877 B
Bash
Executable File

#!/bin/bash -e
SINK='@DEFAULT_AUDIO_SINK@'
NOTIFY=(notify-send -t 1000 -a "$(basename "$0")" -u low)
function update_vol() {
if [[ "$1" =~ ^(-|\+)* ]]; then
CUR="$((CUR - CUR % $1 + $1))"
[ "$CUR" -lt 0 ] && CUR=0
[ "$CUR" -gt 150 ] && CUR=150
else
CUR="$1"
fi
wpctl set-volume "$SINK" "$CUR%"
}
read -r _ CUR MUTE < <(wpctl get-volume "$SINK")
CUR="${CUR/#0/}"; CUR="${CUR/#./}"
if [ -z "$1" ]; then
echo "$CUR"
exit
elif [ "$1" == 'm' ] && [ -z "$MUTE" ]; then
wpctl set-mute "$SINK" 1
"${NOTIFY[@]}" -i audio-volume-muted -h string:synchronous:vol "Mute"
else
if [[ "$1" =~ [0-9] ]]; then
update_vol "$1"
fi
[ -n "$MUTE" ] && wpctl set-mute "$SINK" 0
"${NOTIFY[@]}" -h string:synchronous:vol -h int:value:"$CUR" "$CUR%"
fi
# update sbar
kill -34 "$(cat "$HOME/.cache/pidofbar")"