#!/bin/bash
set -e

SINK='@DEFAULT_SINK@'
CUR_FILE=/var/tmp/current_volume

set +e
CUR="$(cat "$CUR_FILE" || echo 50)"
set -e

CUR="$((CUR - CUR % "$1"))"

case "${1:0:1}" in
    '')
        exit 1
        ;;
    '+'|'-')
        NEW="$((CUR + "$1"))"
        ;;
    *)
        NEW="$1"
        ;;
esac

[ "$NEW" -lt 0 ] && NEW=0
[ "$NEW" -gt 100 ] && NEW=100

pactl set-sink-volume "$SINK" "$NEW%"
pactl set-sink-mute "$SINK" 0

echo "$NEW" > "$CUR_FILE"
echo "$NEW"
