Merge pull request #56 from CaderIdris/add-icon-support

Add Icon Support to Linux
This commit is contained in:
Michael Aquilina 2024-04-24 13:24:21 +01:00 committed by GitHub
commit 4eb63b7c1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 36 additions and 2 deletions

View file

@ -162,6 +162,17 @@ then all the values in ``AUTO_NOTIFY_IGNORE`` are not used.
export AUTO_NOTIFY_WHITELIST=("apt-get" "docker") export AUTO_NOTIFY_WHITELIST=("apt-get" "docker")
**Adding an icon - Linux**
If you wish to have an icon displayed on command success and/or failure, you can do so by defining the environmental variables ``AUTO_NOTIFY_ICON_SUCCESS`` and ``AUTO_NOTIFY_ICON_FAILURE`` respectively.
::
export AUTO_NOTIFY_ICON_SUCCESS=/path/to/success/icon.png
export AUTO_NOTIFY_ICON_FAILURE=/path/to/failure/icon.png
Temporarily Disabling Notifications Temporarily Disabling Notifications
----------------------------------- -----------------------------------

View file

@ -6,6 +6,7 @@ export AUTO_NOTIFY_VERSION="0.8.1"
# Threshold in seconds for when to automatically show a notification # Threshold in seconds for when to automatically show a notification
[[ -z "$AUTO_NOTIFY_THRESHOLD" ]] && [[ -z "$AUTO_NOTIFY_THRESHOLD" ]] &&
export AUTO_NOTIFY_THRESHOLD=10 export AUTO_NOTIFY_THRESHOLD=10
# List of commands/programs to ignore sending notifications for # List of commands/programs to ignore sending notifications for
[[ -z "$AUTO_NOTIFY_IGNORE" ]] && [[ -z "$AUTO_NOTIFY_IGNORE" ]] &&
export AUTO_NOTIFY_IGNORE=( export AUTO_NOTIFY_IGNORE=(
@ -52,11 +53,18 @@ function _auto_notify_message() {
if [[ "$platform" == "Linux" ]]; then if [[ "$platform" == "Linux" ]]; then
local urgency="normal" local urgency="normal"
local transient="--hint=int:transient:1" local transient="--hint=int:transient:1"
local icon=${AUTO_NOTIFY_ICON_SUCCESS:-""}
if [[ "$exit_code" != "0" ]]; then if [[ "$exit_code" != "0" ]]; then
urgency="critical" urgency="critical"
transient="" transient=""
icon=${AUTO_NOTIFY_ICON_FAILURE:-""}
fi fi
notify-send "$title" "$body" --app-name=zsh $transient "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME" local icon_arg=""
if [[ -n "$icon" ]]; then
icon_arg="--icon=$icon"
fi
notify-send "$title" "$body" --app-name=zsh $transient "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME" "$icon_arg"
elif [[ "$platform" == "Darwin" ]]; then elif [[ "$platform" == "Darwin" ]]; then
osascript \ osascript \
-e 'on run argv' \ -e 'on run argv' \

View file

@ -89,7 +89,22 @@
assert "$lines[1]" same_as 'Notification Title: "f bar -r" Completed' assert "$lines[1]" same_as 'Notification Title: "f bar -r" Completed'
assert "$lines[2]" same_as "Notification Body: Total time: 20 seconds" assert "$lines[2]" same_as "Notification Body: Total time: 20 seconds"
assert "$lines[3]" same_as "Exit code: 0" assert "$lines[3]" same_as "Exit code: 0"
assert "$lines[4]" same_as "--app-name=zsh --hint=int:transient:1 --urgency=normal --expire-time=15000" assert "$lines[4]" same_as "--app-name=zsh --hint=int:transient:1 --urgency=normal --expire-time=15000 "
}
@test 'auto-notify-send sends notification and icon on Linux on success' {
AUTO_COMMAND="f bar -r"
AUTO_COMMAND_FULL="foo bar -r"
AUTO_COMMAND_START=11080
AUTO_NOTIFY_EXPIRE_TIME=15000
AUTO_NOTIFY_ICON_SUCCESS=/path/to/success/icon.png
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=normal --expire-time=15000 --icon=/path/to/success/icon.png"
} }
@test 'auto-notify-send sends notification on macOS' { @test 'auto-notify-send sends notification on macOS' {