From 5c39901fc7cba49c70dc29c5dafa727e79c6b0d9 Mon Sep 17 00:00:00 2001 From: Michael Aquilina Date: Sat, 17 Aug 2019 16:42:15 +0100 Subject: [PATCH 1/2] Print warning if notify-send is a missing dependency --- auto-notify.plugin.zsh | 10 +++++++++- tests/test_plugin.zunit | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index 525d8a3..9168f99 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -122,4 +122,12 @@ function enable_auto_notify() { } _auto_notify_reset_tracking -enable_auto_notify + + +platform="$(uname)" +if [[ "$platform" == "Linux" ]] && ! type notify-send > /dev/null; then + printf "'notify-send' must be installed for zsh-auto-notify to work\n" + printf "Please install it with your relevant package manager\n" +else + enable_auto_notify +fi diff --git a/tests/test_plugin.zunit b/tests/test_plugin.zunit index f0e108f..bbcaa4c 100644 --- a/tests/test_plugin.zunit +++ b/tests/test_plugin.zunit @@ -1,23 +1,57 @@ #!/usr/bin/env zunit @setup { - load "../auto-notify.plugin.zsh" + function uname { + printf "Linux" + } + # Mock function for passing builds where we don't + # really need notify-send to be installed (e.g. Mac OSX) + function notify-send { + } } @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 + } + + run load "../auto-notify.plugin.zsh" + + assert "$lines[1]" same_as "'notify-send' must be installed for zsh-auto-notify to work" + assert "$lines[2]" same_as "Please install it with your relevant package manager" + +@test 'dont load auto-notify if notify-send is not installed' { + function type { + return 1 + } + + load "../auto-notify.plugin.zsh" + + assert "_auto_notify_track" not_in $preexec_functions + assert "_auto_notify_send" not_in $precmd_functions +} + + @test 'hook functions are loaded by default' { + load "../auto-notify.plugin.zsh" + assert '_auto_notify_track' in $preexec_functions assert '_auto_notify_send' in $precmd_functions } @test 'enable/disable auto-notify' { + load "../auto-notify.plugin.zsh" + disable_auto_notify assert '_auto_notify_track' not_in $preexec_functions assert '_auto_notify_send' not_in $precmd_functions From 0b7a0396893e8ead9759e5749b5eada5d00a3a96 Mon Sep 17 00:00:00 2001 From: Michael Aquilina Date: Sat, 17 Aug 2019 16:50:58 +0100 Subject: [PATCH 2/2] Bump version to 0.6.0 --- CHANGELOG.md | 4 ++++ auto-notify.plugin.zsh | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e5c070..fa30c32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog for zsh-auto-notify ============================= +0.6.0 +----- +* Display warning and disable auto-notify if notify-send is not installed (Linux only) + 0.5.1 ----- * Improved handling of MacOS notifications via #16 (Thanks @dmitmel!) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index 9168f99..c44d04e 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -1,4 +1,4 @@ -export AUTO_NOTIFY_VERSION="0.5.1" +export AUTO_NOTIFY_VERSION="0.6.0" # Time it takes for a notification to expire export AUTO_NOTIFY_EXPIRE_TIME=8000