This commit is contained in:
Marek Ištok 2024-06-23 10:24:35 -03:00 committed by GitHub
commit c45e39712e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 2 deletions

View file

@ -129,6 +129,17 @@ NOTE: This configuration option currently only works for Linux.
# Set notification expiry to 10 seconds
export AUTO_NOTIFY_EXPIRE_TIME=10000
**Notification Urgency Level**
By default, commands that exit successfully (with code 0) will send out a notification with the urgency level of "normal", while commands that exit with an error (code > 0), will use level "critical".
On some systems (e.g. KDE or Gnome) critical notifications are not desirable as they might never expire.
You can override notification urgency levels by setting the appropriate environment variables ``AUTO_NOTIFY_URGENCY_ON_SUCCESS`` or ``AUTO_NOTIFY_URGENCY_ON_ERROR`` to either ``low``, ``normal``, or ``critical``.
NOTE: This configuration option currently only works for Linux.
::
# Set notification urgency level on error to normal
export AUTO_NOTIFY_URGENCY_ON_ERROR="normal"
**Ignored Commands**

View file

@ -23,6 +23,12 @@ export AUTO_NOTIFY_VERSION="0.10.2"
'ssh'
'nano'
)
# Default notification urgency for successful exit codes
[[ -z "$AUTO_NOTIFY_URGENCY_ON_SUCCESS" ]] &&
export AUTO_NOTIFY_URGENCY_ON_SUCCESS="normal"
# Default notification urgency for error exit codes
[[ -z "$AUTO_NOTIFY_URGENCY_ON_ERROR" ]] &&
export AUTO_NOTIFY_URGENCY_ON_ERROR="critical"
function _auto_notify_format() {
local MESSAGE="$1"
@ -51,11 +57,11 @@ function _auto_notify_message() {
body="$(_auto_notify_format "$text" "$command" "$elapsed" "$exit_code")"
if [[ "$platform" == "Linux" ]]; then
local urgency="normal"
local urgency="$AUTO_NOTIFY_URGENCY_ON_SUCCESS"
local transient="--hint=int:transient:1"
local icon=${AUTO_NOTIFY_ICON_SUCCESS:-""}
if [[ "$exit_code" != "0" ]]; then
urgency="critical"
urgency="$AUTO_NOTIFY_URGENCY_ON_ERROR"
transient=""
icon=${AUTO_NOTIFY_ICON_FAILURE:-""}
fi

View file

@ -155,3 +155,19 @@
assert "$lines[1]" same_as 'Notification Title: doom -i has completed in 45s yo'
assert "$lines[2]" same_as "Notification Body: doom -i exited with code 0"
}
@test 'auto-notify-send sends notification with low urgency' {
AUTO_COMMAND="f bar -r"
AUTO_COMMAND_FULL="foo bar -r"
AUTO_COMMAND_START=11080
AUTO_NOTIFY_URGENCY_ON_SUCCESS="low"
AUTO_NOTIFY_URGENCY_ON_ERROR="critical"
AUTO_NOTIFY_EXPIRE_TIME=8000
run _auto_notify_send
assert $state equals 0
assert "$lines[1]" same_as 'Notification Title: "f bar -r" Completed'
assert "$lines[2]" same_as "Notification Body: Total time: 20 seconds"
assert "$lines[3]" same_as "Exit code: 0"
assert "$lines[4]" same_as "--app-name=zsh --hint=int:transient:1 --urgency=low --expire-time=8000"
}