diff --git a/files/dwm/volume.function b/files/dwm/volume.function index db8c457..6807ff0 100755 --- a/files/dwm/volume.function +++ b/files/dwm/volume.function @@ -35,6 +35,9 @@ alias volume-help="volume-usage" alias vol-h="volume-help" function volume { + + ## Check Params ## + if [[ "$1" == "--help" || "$1" == "help" || "$1" == "-h" ]]; then volume-usage 1 return 1 @@ -46,13 +49,16 @@ function volume { return 0 fi - if [[ "$1" == *"%"* || "$2" == *"%"* ]]; then - set -- "${1//%/}" "${2//%/}" - fi + ## Parse Params ## dir="" amt="" + # Remove percent signs. + if [[ "$1" == *"%"* || "$2" == *"%"* ]]; then + set -- "${1//%/}" "${2//%/}" + fi + # Check if format is written text. if [[ "$1" == "full" || "$1" == "max" ]]; then amt=100 @@ -101,6 +107,7 @@ function volume { amt="$1" fi + ## Error Checking ## regex='^[0-9]+$' if ! [[ $amt =~ $regex ]]; then echo "> ERROR: Amount '$amt' does not seem like a integer." @@ -108,6 +115,8 @@ function volume { return 2 fi + ## Main ## + if [[ -n "$dir" && -n "$amt" ]]; then echo "> Changing volume by '$dir$amt%'." amixer -q sset Master ${amt}%${dir} @@ -122,7 +131,7 @@ function volume { return 0 fi - echo "Error: Should not have made it here. Please report this to the developer." + echo "> ERROR: Should not have made it here. Please report this to the developer." echo "$0 $1 $2" return 7 }