diff --git a/CHANGELOG.md b/CHANGELOG.md index 5387547..400999d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,18 @@ Changelog for zsh-auto-notify ============================= +0.10.2 +------ +* Use preferable array argument expansion for flexible parameters + +0.10.1 +------ +* Fix regression where not setting icon on Linux would cause issues (#59 #58) + +0.10.0 +----- +* Allow specifying an icon with notify-send backends + 0.8.0 ----- * Change notify-send application title to `zsh` diff --git a/README.rst b/README.rst index 70ea746..a69648d 100644 --- a/README.rst +++ b/README.rst @@ -162,6 +162,17 @@ then all the values in ``AUTO_NOTIFY_IGNORE`` are not used. 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 ----------------------------------- diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index 64174b9..8709265 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -1,4 +1,4 @@ -export AUTO_NOTIFY_VERSION="0.8.1" +export AUTO_NOTIFY_VERSION="0.10.2" # Time it takes for a notification to expire [[ -z "$AUTO_NOTIFY_EXPIRE_TIME" ]] && @@ -6,6 +6,7 @@ export AUTO_NOTIFY_VERSION="0.8.1" # Threshold in seconds for when to automatically show a notification [[ -z "$AUTO_NOTIFY_THRESHOLD" ]] && export AUTO_NOTIFY_THRESHOLD=10 + # List of commands/programs to ignore sending notifications for [[ -z "$AUTO_NOTIFY_IGNORE" ]] && export AUTO_NOTIFY_IGNORE=( @@ -52,11 +53,20 @@ function _auto_notify_message() { if [[ "$platform" == "Linux" ]]; then local urgency="normal" local transient="--hint=int:transient:1" + local icon=${AUTO_NOTIFY_ICON_SUCCESS:-""} if [[ "$exit_code" != "0" ]]; then urgency="critical" transient="" + icon=${AUTO_NOTIFY_ICON_FAILURE:-""} fi - notify-send "$title" "$body" --app-name=zsh $transient "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME" + + local arguments=("$title" "$body" "--app-name=zsh" "$transient" "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME") + + if [[ -n "$icon" ]]; then + arguments+=("--icon=$icon") + fi + notify-send ${arguments[@]} + elif [[ "$platform" == "Darwin" ]]; then osascript \ -e 'on run argv' \ diff --git a/tests/test_auto_notify_send.zunit b/tests/test_auto_notify_send.zunit index 4748b2b..49e477f 100644 --- a/tests/test_auto_notify_send.zunit +++ b/tests/test_auto_notify_send.zunit @@ -92,6 +92,21 @@ 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' { AUTO_COMMAND="f bar -r" AUTO_COMMAND_FULL="foo bar -r" diff --git a/tests/test_plugin.zunit b/tests/test_plugin.zunit index bbcaa4c..e1c1543 100644 --- a/tests/test_plugin.zunit +++ b/tests/test_plugin.zunit @@ -10,16 +10,6 @@ } } -@test 'version exported' { - git_version="$(git tag --list | sort -V | tail -1)" - git tag --list - - load "../auto-notify.plugin.zsh" - - assert "$AUTO_NOTIFY_VERSION" is_not_empty - assert "$AUTO_NOTIFY_VERSION" same_as "$git_version" -} - @test 'print warning if notify-send is not installed' { function type { return 1