Added the notification timeout optional flag

This commit is contained in:
Karma Riuk 2021-03-04 01:36:53 +01:00
parent cfcb423770
commit a8287257bb

View File

@ -14,7 +14,8 @@ ADDITIONAL_FLAGS=("--allow-boost")
## Default values ## Default values
NOTIFICATION_ENABLED=1 NOTIFICATION_ENABLED=1
NOTIFICATION_TIMEOUT=5 NOTIFICATION_TIMEOUT=5000
CONFIG_PATH="$XDG_CONFIG_HOME/`basename $0`/config.ini" CONFIG_PATH="$XDG_CONFIG_HOME/`basename $0`/config.ini"
VERBOSE=0 VERBOSE=0
@ -26,7 +27,7 @@ VOLUME_MIN=5
## Args ## Args
OPTIONAL_FLAGS=("-v" "--verbose" "-c" "--config" "-n" "--notifcation" "-N" "--no-notification") OPTIONAL_FLAGS=("-t" "--notification-timeout" "-v" "--verbose" "-c" "--config" "-n" "--notifcation" "-N" "--no-notification" "-h" "--help")
verbose () { verbose () {
[[ $VERBOSE -eq 1 ]] && return 0 || return 1 [[ $VERBOSE -eq 1 ]] && return 0 || return 1
@ -46,7 +47,7 @@ notify () {
icon="audio-volume-high" icon="audio-volume-high"
fi fi
local cmd="dunstify -h int:value:$volume -h string:x-dunst-stack-tag:volume -i \"$icon\" \"Volume ($volume%)\"" local cmd="dunstify -h int:value:$volume -t $NOTIFICATION_TIMEOUT -h string:x-dunst-stack-tag:volume -i \"$icon\" \"Volume ($volume%)\""
[[ $NOTIFICATION_ENABLED -eq 1 ]] && sh -c "$cmd" [[ $NOTIFICATION_ENABLED -eq 1 ]] && sh -c "$cmd"
verbose && ( [[ $NOTIFICATION_ENABLED -eq 1 ]] && echo "Notified with \`$cmd\`" || echo "Didn't notify" ) verbose && ( [[ $NOTIFICATION_ENABLED -eq 1 ]] && echo "Notified with \`$cmd\`" || echo "Didn't notify" )
} }
@ -66,7 +67,7 @@ volume_down_by () {
verbose && echo "Decreasing volume by $1, with \`$cmd\`" verbose && echo "Decreasing volume by $1, with \`$cmd\`"
verbose && echo "Volume before command: $(get_volume)" verbose && echo "Volume before command: $(get_volume)"
$cmd sh -c "$cmd"
verbose && echo "Volume after command: $(get_volume)" verbose && echo "Volume after command: $(get_volume)"
notify notify
} }
@ -76,7 +77,7 @@ volume_set () {
verbose && echo "Setting the volume to $1, with \`$cmd\`" verbose && echo "Setting the volume to $1, with \`$cmd\`"
verbose && echo "Volume before command: $(get_volume)" verbose && echo "Volume before command: $(get_volume)"
$cmd sh -c "$cmd"
verbose && echo "Volume after command: $(get_volume)" verbose && echo "Volume after command: $(get_volume)"
notify notify
} }
@ -96,7 +97,7 @@ volume_big_down () {
volume_up () { volume_up () {
local cmd="volume_up_by $NORMAL_DELTA" local cmd="volume_up_by $NORMAL_DELTA"
verbose && echo "Increasing the volume, with \`$cmd\`" verbose && echo "Increasing the volume, with \`$cmd\`"
$cmd sh -c "$cmd"
} }
volume_down () { volume_down () {
@ -110,7 +111,7 @@ toggle_mute() {
verbose && echo "Toggling the mute, with \`$cmd\`" verbose && echo "Toggling the mute, with \`$cmd\`"
verbose && echo "Mute state before command: $(get_mute)" verbose && echo "Mute state before command: $(get_mute)"
$cmd sh -c "$cmd"
verbose && echo "Mute state after command: $(get_mute)" verbose && echo "Mute state after command: $(get_mute)"
notify notify
} }
@ -121,7 +122,7 @@ mute () {
verbose && echo "Setting the mute on, with \`$cmd\`" verbose && echo "Setting the mute on, with \`$cmd\`"
verbose && echo "Mute state before command: $(get_mute)" verbose && echo "Mute state before command: $(get_mute)"
$cmd sh -c "$cmd"
verbose && echo "Mute state after command: $(get_mute)" verbose && echo "Mute state after command: $(get_mute)"
notify notify
} }
@ -131,17 +132,17 @@ unmute () {
verbose && echo "Setting the mute off, with \`$cmd\`" verbose && echo "Setting the mute off, with \`$cmd\`"
verbose && echo "Mute state before command: $(get_mute)" verbose && echo "Mute state before command: $(get_mute)"
$cmd sh -c "$cmd"
verbose && echo "Mute state after command: $(get_mute)" verbose && echo "Mute state after command: $(get_mute)"
notify notify
} }
get_volume () { get_volume () {
$VOLUME_CONTROLLER ${ADDITIONAL_FLAGS[@]} $GET_VOLUME_FLAG sh -c "$VOLUME_CONTROLLER ${ADDITIONAL_FLAGS[@]} $GET_VOLUME_FLAG"
} }
get_mute () { get_mute () {
$VOLUME_CONTROLLER ${ADDITIONAL_FLAGS[@]} $GET_MUTE_FLAG sh -c "$VOLUME_CONTROLLER ${ADDITIONAL_FLAGS[@]} $GET_MUTE_FLAG"
} }
usage() { usage() {
@ -164,12 +165,14 @@ Options:
-t, --toggle toggle mute -t, --toggle toggle mute
-g, --get-volume get volume -g, --get-volume get volume
-G, --get-mute get mute -G, --get-mute get mute
-h, -?, --help show this message
Optional arguments: Optional arguments:
-t, --notification-timeout arg forces the notification timeout, in milliseconds (overrides the configuation setting,
the default value is $NOTIFICATION_TIMEOUT)
-n, --notification forces the notification to appear (overrides the configuration setting) -n, --notification forces the notification to appear (overrides the configuration setting)
-N, --no-notification forces the notification NOT to appear (overrides the configuration setting) -N, --no-notification forces the notification NOT to appear (overrides the configuration setting)
-v, --verbose print each step the script passes through -v, --verbose print each step the script passes through
-h, -?, --help show this message
EOF EOF
} }
@ -185,6 +188,11 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then #if '__name__' == '__main__'
verbose && echo "Setting \$VERBOSE to true (\$VERBOSE=$VERBOSE)" verbose && echo "Setting \$VERBOSE to true (\$VERBOSE=$VERBOSE)"
shift shift
;; ;;
-t|--notification-timeout)
NOTIFICATION_TIMEOUT="$2";
verbose && echo "Setting \$NOTIFICATION_TIMEOUT to $2 (\$NOTIFICATION_TIMEOUT=$NOTIFICATION_TIMEOUT)"
shift 2
;;
-c|--config) -c|--config)
CONFIG_PATH="$2"; CONFIG_PATH="$2";
verbose && echo "Setting \$CONFIG_PATH to $2 (\$CONFIG_PATH=$CONFIG_PATH)" verbose && echo "Setting \$CONFIG_PATH to $2 (\$CONFIG_PATH=$CONFIG_PATH)"
@ -200,6 +208,11 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then #if '__name__' == '__main__'
verbose && echo "Setting \$NOTIFICATION_ENABLED to false (\$NOTIFICATION_ENABLED=$NOTIFICATION_ENABLED)" verbose && echo "Setting \$NOTIFICATION_ENABLED to false (\$NOTIFICATION_ENABLED=$NOTIFICATION_ENABLED)"
shift shift
;; ;;
-h|-\?|--help)
verbose && echo "Detected -h, -? or --help"
usage
shift
;;
esac esac
done done
@ -253,8 +266,7 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then #if '__name__' == '__main__'
verbose && echo "Detected -G or --get-mute" verbose && echo "Detected -G or --get-mute"
get_mute get_mute
;; ;;
-h|-\?|--help) "")
verbose && echo "Detected -h, -? or --help"
usage usage
;; ;;
*) *)