2020-10-28 15:49:32 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-02-01 16:05:35 +01:00
|
|
|
## Default controller values
|
2020-10-28 15:49:32 +01:00
|
|
|
VOLUME_CONTROLLER="pamixer"
|
|
|
|
INCREASE_FLAG="--increase"
|
|
|
|
DECREASE_FLAG="--decrease"
|
|
|
|
SET_VOLUME_FLAG="--set-volume"
|
|
|
|
SET_MUTE_FLAG="--mute"
|
2020-10-28 16:05:06 +01:00
|
|
|
SET_UNMUTE_FLAG="--unmute"
|
2020-10-28 15:49:32 +01:00
|
|
|
TOGGLE_MUTE_FLAG="--toggle-mute"
|
2021-02-01 16:05:35 +01:00
|
|
|
GET_VOLUME_FLAG="--get-volume"
|
|
|
|
GET_MUTE_FLAG="--get-mute"
|
2020-10-28 15:49:32 +01:00
|
|
|
ADDITIONAL_FLAGS=("--allow-boost")
|
|
|
|
|
2021-02-01 16:05:35 +01:00
|
|
|
## Default values
|
2020-10-28 15:49:32 +01:00
|
|
|
NOTIFICATION=1
|
2021-02-01 16:05:35 +01:00
|
|
|
CONFIG_PATH="$XDG_CONFIG_HOME/`basename`/config.ini"
|
|
|
|
VERBOSE=0
|
|
|
|
|
|
|
|
NORMAL_DELTA=5
|
|
|
|
BIG_DELTA=5
|
|
|
|
|
|
|
|
## Args
|
|
|
|
OPTIONAL_FLAGS=("-c" "--config" "-n" "--notifcation" "-N" "--no-notification")
|
2020-10-28 15:49:32 +01:00
|
|
|
|
|
|
|
volume_up_by () {
|
2021-02-01 16:05:35 +01:00
|
|
|
local cmd="$VOLUME_CONTROLLER ${ADDITIONAL_FLAGS[@]} $INCREASE_FLAG $1"
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Increasing volume by $1, with \`$cmd\`"
|
|
|
|
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Volume before command: $(get_volume)"
|
|
|
|
$cmd
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Volume after command: $(get_volume)"
|
|
|
|
|
2020-10-28 15:49:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
volume_down_by () {
|
2021-02-28 07:35:23 +01:00
|
|
|
local cmd="$VOLUME_CONTROLLER ${ADDITIONAL_FLAGS[@]} $DECREASE_FLAG $1"
|
2021-02-01 16:05:35 +01:00
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Decreasing volume by $1, with \`$cmd\`"
|
|
|
|
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Volume before command: $(get_volume)"
|
|
|
|
$cmd
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Volume after command: $(get_volume)"
|
2020-10-28 15:49:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
volume_set () {
|
2021-02-28 07:35:23 +01:00
|
|
|
local cmd="$VOLUME_CONTROLLER ${ADDITIONAL_FLAGS[@]} $SET_VOLUME_FLAG $1"
|
2021-02-01 16:05:35 +01:00
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Setting the volume to $1, with \`$cmd\`"
|
|
|
|
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Volume before command: $(get_volume)"
|
|
|
|
$cmd
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Volume after command: $(get_volume)"
|
2020-10-28 15:49:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
volume_big_up () {
|
2021-02-28 07:35:23 +01:00
|
|
|
local cmd="volume_up_by $BIG_DELTA"
|
2021-02-01 16:05:35 +01:00
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Increasing the volume alot, with \`$cmd\`"
|
|
|
|
$cmd
|
2020-10-28 15:49:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
volume_big_down () {
|
2021-02-28 07:35:23 +01:00
|
|
|
local cmd="volume_down_by $BIG_DELTA"
|
2021-02-01 16:05:35 +01:00
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Decreasing the volume alot, with \`$cmd\`"
|
|
|
|
$cmd
|
2020-10-28 15:49:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
volume_up () {
|
2021-02-28 07:35:23 +01:00
|
|
|
local cmd="volume_up_by $NORMAL_DELTA"
|
2021-02-01 16:05:35 +01:00
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Increasing the volume, with \`$cmd\`"
|
|
|
|
$cmd
|
2020-10-28 15:49:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
volume_down () {
|
2021-02-28 07:35:23 +01:00
|
|
|
local cmd="volume_down_by $NORMAL_DELTA"
|
2021-02-01 16:05:35 +01:00
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Decreasing the volume, with \`$cmd\`"
|
|
|
|
$cmd
|
2020-10-28 15:49:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
toggle_mute() {
|
2021-02-28 07:35:23 +01:00
|
|
|
local cmd="$VOLUME_CONTROLLER $TOGGLE_MUTE_FLAG"
|
2021-02-01 16:05:35 +01:00
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Toggling the mute, with \`$cmd\`"
|
|
|
|
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Mute state before command: $(get_mute)"
|
|
|
|
$cmd
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Mute state after command: $(get_mute)"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mute () {
|
2021-02-28 07:35:23 +01:00
|
|
|
local cmd="$VOLUME_CONTROLLER $SET_UNMUTE_FLAG"
|
2021-02-01 16:05:35 +01:00
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Setting the mute on, with \`$cmd\`"
|
|
|
|
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Mute state before command: $(get_mute)"
|
|
|
|
$cmd
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Mute state after command: $(get_mute)"
|
2020-10-28 15:49:32 +01:00
|
|
|
}
|
|
|
|
|
2021-02-01 16:05:35 +01:00
|
|
|
unmute () {
|
2021-02-28 07:35:23 +01:00
|
|
|
local cmd="$VOLUME_CONTROLLER $SET_MUTE_FLAG"
|
2021-02-01 16:05:35 +01:00
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Setting the mute off, with \`$cmd\`"
|
|
|
|
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Mute state before command: $(get_mute)"
|
|
|
|
$cmd
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Mute state after command: $(get_mute)"
|
|
|
|
}
|
2020-10-28 16:05:06 +01:00
|
|
|
|
2021-02-01 16:05:35 +01:00
|
|
|
get_volume () {
|
|
|
|
$VOLUME_CONTROLLER ${ADDITIONAL_FLAGS[@]} $GET_VOLUME_FLAG
|
2020-10-28 16:05:06 +01:00
|
|
|
}
|
|
|
|
|
2021-02-01 16:05:35 +01:00
|
|
|
get_mute () {
|
|
|
|
$VOLUME_CONTROLLER ${ADDITIONAL_FLAGS[@]} $GET_MUTED_FLAG
|
2020-10-28 15:49:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
cat << EOF
|
|
|
|
volumectl - A configurable bash script that makes your life easier in controlling you volume and notifying it.
|
|
|
|
|
2021-02-01 16:05:35 +01:00
|
|
|
Usage: volumectl [-v|--verbose] [-c|--config path] [-n|-N] -option [arg]
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-i [arg], --increase [arg] increase the volume by the "normal" amount or by the [arg] amount
|
|
|
|
-d [arg], --decrease [arg] decrease the volume by the "normal" amount or by the [arg] amount
|
|
|
|
-I, --big-increase increase the volume by the "big" amount
|
|
|
|
-D, --big-decrease decrease the volume by the "big" amount
|
|
|
|
-s arg, --set arg set volume to arg
|
|
|
|
-m, --mute mute
|
|
|
|
-u, --unmute unmute
|
|
|
|
-t, --toggle toggle mute
|
|
|
|
-g, --get-volume get volume
|
|
|
|
-G, --get-mute get mute
|
|
|
|
-h, -?, --help show this message
|
|
|
|
|
|
|
|
Optional arguments:
|
2020-10-28 15:49:32 +01:00
|
|
|
-n, --notification forces the notification to appear (overrides the configuration setting)
|
|
|
|
-N, --no-notification forces the notification NOT to appear (overrides the configuration setting)
|
2021-02-01 16:05:35 +01:00
|
|
|
-v, --verbose print each step the script passes through
|
2020-10-28 15:49:32 +01:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then #if '__name__' == '__main__'
|
|
|
|
# check if the notification is being forced or not
|
2021-02-01 16:05:35 +01:00
|
|
|
|
|
|
|
while [[ " ${OPTIONAL_FLAGS[@]} " =~ " $1 " ]]; do
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Checking for optional arguments"
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
-v|--verbose)
|
|
|
|
VERBOSE=1
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Setting VERBOSE to true (VERBOSE=$VERBOSE)"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-c|--config)
|
|
|
|
CONFIG_PATH="$2";
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Setting CONFIG_PATH to $2 (CONFIG_PATH=$CONFIG_PATH)"
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
-n|--notification)
|
|
|
|
NOTIFICATION=1
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Setting NOTIFICATION to true (NOTIFICATION=$NOTIFICATION)"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-N|--no-notification)
|
|
|
|
NOTIFICATION=0;
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Setting NOTIFICATION to false (NOTIFICATION=$NOTIFICATION)"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Looking at the argument"
|
2020-10-28 15:49:32 +01:00
|
|
|
case $1 in
|
|
|
|
-i|--increase)
|
2021-02-01 16:05:35 +01:00
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Detected -i or --increase, with argument '$2'"
|
2020-10-28 15:49:32 +01:00
|
|
|
[[ -z "$2" ]] && volume_up || volume_up_by $2
|
|
|
|
;;
|
|
|
|
-I|--big-increase)
|
2021-02-01 16:05:35 +01:00
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Detected -I or --big-increase"
|
2020-10-28 15:49:32 +01:00
|
|
|
volume_big_up
|
|
|
|
;;
|
|
|
|
-d|--decrease)
|
2021-02-01 16:05:35 +01:00
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Detected -d or --decrease, with argument '$2'"
|
|
|
|
[[ -z "Detected -i or --increase" ]] && volume_down || volume_down_by $2
|
2020-10-28 15:49:32 +01:00
|
|
|
;;
|
|
|
|
-D|--big-decrease)
|
2021-02-01 16:05:35 +01:00
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Detected -D or --big-decrease"
|
2020-10-28 15:49:32 +01:00
|
|
|
volume_big_down
|
|
|
|
;;
|
|
|
|
-s|--set-volume)
|
2021-02-01 16:05:35 +01:00
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Detected -s or --set-volume, with argument '$2'"
|
|
|
|
[[ -z "$2" ]] && echo "Error, missing value to set volume" 1>&2 && exit 1 || volume_set $2
|
2020-10-28 16:05:06 +01:00
|
|
|
;;
|
2020-10-28 15:49:32 +01:00
|
|
|
-m|--set-mute)
|
2021-02-01 16:05:35 +01:00
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Detected -m or --mute"
|
|
|
|
mute
|
|
|
|
;;
|
|
|
|
-u|--ummute)
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Detected -u or --unmute"
|
|
|
|
unmute
|
2020-10-28 15:49:32 +01:00
|
|
|
;;
|
|
|
|
-t|--toggle-mute)
|
2021-02-01 16:05:35 +01:00
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Detected -t or --toggle-mute"
|
2020-10-28 15:49:32 +01:00
|
|
|
toggle_mute
|
|
|
|
;;
|
2021-02-01 16:05:35 +01:00
|
|
|
-g|--get-volume)
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Detected -g or --get-volume"
|
|
|
|
get_volume
|
|
|
|
;;
|
|
|
|
-G|--get-mute)
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Detected -G or --get-mute"
|
|
|
|
get_mute
|
|
|
|
;;
|
|
|
|
-h|-\?|--help)
|
|
|
|
[[ $VERBOSE -eq 1 ]] && echo "Detected -h, -? or --help"
|
2020-10-28 15:49:32 +01:00
|
|
|
usage
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unrecognized '$1' flag or argument"
|
|
|
|
echo "Try 'volumectl -h' for more information"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
2021-02-28 07:35:23 +01:00
|
|
|
|