dotfiles/.local/bin/vol
2024-06-23 11:51:38 +02:00

35 lines
904 B
Bash
Executable File

#!/bin/bash -e
SINK='@DEFAULT_AUDIO_SINK@'
NOTIFY=(notify-send -t 1000 -u low)
function update_vol() {
if [[ "$1" =~ ^(-|\+)* ]]; then
CUR="$(($CUR + $1 - $CUR % $1 + $CUR % $1 * 10 / $1 / 5 * $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="$(("10#${CUR/./}"))"
if [ -z "$1" ]; then
echo "$CUR"
exit
elif [ "$1" == 'm' ] && [ -z "$MUTE" ]; then
wpctl set-mute "$SINK" 1
"${NOTIFY[@]}" -i audio-volume-muted-symbolic -h string:synchronous:vol "Mute"
else
if [[ "$1" =~ [0-9] ]]; then
update_vol "$1"
fi
[ -n "$MUTE" ] && wpctl set-mute "$SINK" 0
"${NOTIFY[@]}" -i audio-volume-high-symbolic -h string:synchronous:vol -h int:value:"$CUR" "$CUR%"
fi
kill -35 "$(cat "$HOME/.cache/pidofbar")"