#!/bin/sh
#
# Switch mixer between on and off, remembering volume.
#

if mixer vol | grep -q 0:0; then
	newvol=`cat ~/.mixswitchvolume`
	# Mixer is off - restore volume
	mixer vol $newvol 2>&1 > /dev/null
	if [ -t 1 ]; then
	    echo "Restored volume $newvol"
	fi
else
	# Mixer is on - store volume, and turn it off
	oldvol=`mixer vol | awk '{print $7}'`
	echo $oldvol > ~/.mixswitchvolume
	mixer vol 0 > /dev/null
	if [ -t 1 ]; then
	    echo "Suspended volume $oldvol"
	fi
fi
