53 lines
996 B
Bash
Executable File
53 lines
996 B
Bash
Executable File
#!/bin/bash -e
|
|
|
|
case "$1" in
|
|
s)
|
|
DEV='@DEFAULT_AUDIO_SINK@'
|
|
SIG=35
|
|
;;
|
|
m)
|
|
DEV='@DEFAULT_AUDIO_SOURCE@'
|
|
SIG=36
|
|
;;
|
|
*)
|
|
exit 1
|
|
;;
|
|
esac
|
|
shift
|
|
|
|
function update_vol() {
|
|
case "$1" in
|
|
+*|-*)
|
|
# shellcheck disable=SC2017
|
|
CUR=$((CUR + $1 - CUR % $1 + CUR % $1 * 10 / $1 / 5 * $1))
|
|
if [ "$CUR" -lt 0 ]; then
|
|
CUR=0
|
|
elif [ "$CUR" -gt 300 ]; then
|
|
CUR=150
|
|
fi
|
|
;;
|
|
*)
|
|
CUR="$1"
|
|
esac
|
|
wpctl set-volume "$DEV" "$CUR%"
|
|
}
|
|
|
|
read -r _ CUR MUTE < <(wpctl get-volume "$DEV")
|
|
CUR=$(("10#${CUR/./}"))
|
|
|
|
if [ -z "$1" ]; then
|
|
echo "$CUR"
|
|
exit
|
|
elif [ "$1" == 'm' ] && [ -z "$MUTE" ]; then
|
|
wpctl set-mute "$DEV" 1
|
|
else
|
|
if [[ "$1" =~ [0-9] ]]; then
|
|
update_vol "$1"
|
|
fi
|
|
if [ -n "$MUTE" ]; then
|
|
wpctl set-mute "$DEV" 0
|
|
fi
|
|
fi
|
|
|
|
kill "-$SIG" "$(cat "$XDG_CACHE_HOME/pidofbar")"
|