Add configuration options for notification urgency
This commit is contained in:
parent
22b2c61ed1
commit
d50ca23ebe
2 changed files with 24 additions and 2 deletions
|
@ -22,6 +22,12 @@ export AUTO_NOTIFY_VERSION="0.8.1"
|
|||
'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"
|
||||
|
@ -50,10 +56,10 @@ 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"
|
||||
if [[ "$exit_code" != "0" ]]; then
|
||||
urgency="critical"
|
||||
urgency="$AUTO_NOTIFY_URGENCY_ON_ERROR"
|
||||
transient=""
|
||||
fi
|
||||
notify-send "$title" "$body" --app-name=zsh $transient "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME"
|
||||
|
|
|
@ -140,3 +140,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"
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue