Add comments and error consistency.
This commit is contained in:
@@ -35,6 +35,9 @@ alias volume-help="volume-usage"
|
|||||||
alias vol-h="volume-help"
|
alias vol-h="volume-help"
|
||||||
|
|
||||||
function volume {
|
function volume {
|
||||||
|
|
||||||
|
## Check Params ##
|
||||||
|
|
||||||
if [[ "$1" == "--help" || "$1" == "help" || "$1" == "-h" ]]; then
|
if [[ "$1" == "--help" || "$1" == "help" || "$1" == "-h" ]]; then
|
||||||
volume-usage 1
|
volume-usage 1
|
||||||
return 1
|
return 1
|
||||||
@@ -46,13 +49,16 @@ function volume {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$1" == *"%"* || "$2" == *"%"* ]]; then
|
## Parse Params ##
|
||||||
set -- "${1//%/}" "${2//%/}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
dir=""
|
dir=""
|
||||||
amt=""
|
amt=""
|
||||||
|
|
||||||
|
# Remove percent signs.
|
||||||
|
if [[ "$1" == *"%"* || "$2" == *"%"* ]]; then
|
||||||
|
set -- "${1//%/}" "${2//%/}"
|
||||||
|
fi
|
||||||
|
|
||||||
# Check if format is written text.
|
# Check if format is written text.
|
||||||
if [[ "$1" == "full" || "$1" == "max" ]]; then
|
if [[ "$1" == "full" || "$1" == "max" ]]; then
|
||||||
amt=100
|
amt=100
|
||||||
@@ -101,6 +107,7 @@ function volume {
|
|||||||
amt="$1"
|
amt="$1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
## Error Checking ##
|
||||||
regex='^[0-9]+$'
|
regex='^[0-9]+$'
|
||||||
if ! [[ $amt =~ $regex ]]; then
|
if ! [[ $amt =~ $regex ]]; then
|
||||||
echo "> ERROR: Amount '$amt' does not seem like a integer."
|
echo "> ERROR: Amount '$amt' does not seem like a integer."
|
||||||
@@ -108,6 +115,8 @@ function volume {
|
|||||||
return 2
|
return 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
## Main ##
|
||||||
|
|
||||||
if [[ -n "$dir" && -n "$amt" ]]; then
|
if [[ -n "$dir" && -n "$amt" ]]; then
|
||||||
echo "> Changing volume by '$dir$amt%'."
|
echo "> Changing volume by '$dir$amt%'."
|
||||||
amixer -q sset Master ${amt}%${dir}
|
amixer -q sset Master ${amt}%${dir}
|
||||||
@@ -122,7 +131,7 @@ function volume {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
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"
|
echo "$0 $1 $2"
|
||||||
return 7
|
return 7
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user