#!/bin/sh

dev=@DEFAULT_SINK@
! [ "$1" = '-m' ] || { dev=@DEFAULT_SOURCE@; shift; }

vol="$(wpctl get-volume "$dev")"

[ "$vol" != "${vol%\[MUTED\]}" ] && echo "MUTED" && exit
vol="${vol#Volume: }"

split() {
	# For ommiting the . without calling and external program.
	IFS=$2
	set -- $1
	printf '%s' "$@"
}

vol="$(printf "%.0f" "$(split "$vol" ".")")"
echo "$vol"
