37 lines
735 B
Bash
Executable File
37 lines
735 B
Bash
Executable File
#!/bin/bash -e
|
|
|
|
case "$1" in
|
|
s) DEV='@DEFAULT_AUDIO_SINK@' ;;
|
|
m) DEV='@DEFAULT_AUDIO_SOURCE@' ;;
|
|
*) exit 1 ;;
|
|
esac
|
|
|
|
function update_vol() {
|
|
# shellcheck disable=SC2017
|
|
case "$1" in
|
|
+*|-*) CUR=$((CUR + $1 - CUR % $1 + CUR % $1 * 10 / $1 / 5 * $1)) ;;
|
|
*) CUR="$1" ;;
|
|
esac
|
|
wpctl set-volume -l 3 "$DEV" "$CUR%"
|
|
}
|
|
|
|
read -r _ CUR MUTE < <(wpctl get-volume "$DEV")
|
|
CUR=$((10#${CUR/./}))
|
|
|
|
if [ -z "$2" ]; then
|
|
echo "$CUR"
|
|
exit
|
|
fi
|
|
if [ "$2" == 'm' ] && [ -z "$MUTE" ]; then
|
|
wpctl set-mute "$DEV" 1
|
|
else
|
|
if [[ "$2" =~ [0-9] ]]; then
|
|
update_vol "$2"
|
|
fi
|
|
if [ -n "$MUTE" ]; then
|
|
wpctl set-mute "$DEV" 0
|
|
fi
|
|
fi
|
|
|
|
kill -34 "$(cat "$XDG_RUNTIME_DIR/sbar/pid")"
|