#!/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 +*|-*) CUR="$(($CUR + $1 - $CUR % $1 + $CUR % $1 * 10 / $1 / 5 * $1))" [ "$CUR" -lt 0 ] && CUR=0 [ "$CUR" -gt 200 ] && CUR=200 ;; *) 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 [ -n "$MUTE" ] && wpctl set-mute "$DEV" 0 fi kill "-$SIG" "$(cat "$HOME/.cache/pidofbar")"