#!/bin/bash set -e PACTL_SINK='@DEFAULT_SINK@' SINK="$PACTL_SINK" function get_vol() { VOL="$(pactl get-sink-volume "$SINK" 2> /dev/null)" if [ -n "$VOL" ]; then CMD='pactl set-sink-volume' else CMD='amixer sset' SINK='Master' VOL="$(amixer sget "$SINK")" fi } set +e get_vol set -e VOL="$(echo "$VOL" | grep -o -E '[0-9]{,3}%' | head -n 1)" # Remove everything after first '%' VOL="${VOL%%%*}" VOL="$((VOL - VOL % "$1"))" case "${1:0:1}" in '') exit 1 ;; '+'|'-') VOL="$((VOL + "$1"))" ;; *) VOL="$1" ;; esac [ "$VOL" -lt 0 ] && VOL=0 [ "$VOL" -gt 100 ] && VOL=100 $CMD "$SINK" "$VOL%" > /dev/null pactl set-sink-mute "$PACTL_SINK" 0 echo "$VOL"