From bd83266ccf705db0c64ba6e398adac210f2a318b Mon Sep 17 00:00:00 2001 From: Michael Aquilina Date: Sun, 14 Jul 2019 12:16:47 +0100 Subject: [PATCH] Add enable/disable functionality --- README.rst | 8 ++++++++ auto-notify.plugin.zsh | 15 ++++++++++++--- tests/test_auto_notify.zunit | 10 ++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 2d48b3c..b8808f1 100644 --- a/README.rst +++ b/README.rst @@ -9,6 +9,7 @@ has completed. * Usage_ * Requirements_ * Installation_ +* `Temporarily Disabling Notifications` * Contributing_ * `Running Tests`_ @@ -66,6 +67,13 @@ Then add this line to your ``.zshrc``. Make sure it is **before** the line ``sou plugins=(auto-notify $plugins) +Temporarily Disabling Notifications +----------------------------------- + +You can temporarily disable auto notify by running the command ``disable_auto_notify``. + + When you want to re-enable notifications, run the command ``enable_auto_notify``. + Contributing ------------ diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index eb53703..cea50d6 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -45,6 +45,15 @@ function _auto_notify_track() { AUTO_COMMAND_START="$(date +"%s")" } -autoload -U add-zsh-hook -add-zsh-hook preexec _auto_notify_track -add-zsh-hook precmd _auto_notify_send +function disable_auto_notify() { + add-zsh-hook -D preexec _auto_notify_track + add-zsh-hook -D precmd _auto_notify_send +} + +function enable_auto_notify() { + add-zsh-hook preexec _auto_notify_track + add-zsh-hook precmd _auto_notify_send +} + +autoload -Uz add-zsh-hook +enable_auto_notify diff --git a/tests/test_auto_notify.zunit b/tests/test_auto_notify.zunit index 20687e3..6fe8c76 100644 --- a/tests/test_auto_notify.zunit +++ b/tests/test_auto_notify.zunit @@ -26,6 +26,16 @@ assert '_auto_notify_send' in $precmd_functions } +@test 'enable/disable auto-notify' { + disable_auto_notify + assert '_auto_notify_track' not_in $preexec_functions + assert '_auto_notify_send' not_in $precmd_functions + + enable_auto_notify + assert '_auto_notify_track' in $preexec_functions + assert '_auto_notify_send' in $precmd_functions +} + @test 'auto-notify-send does not send notification for short task' { AUTO_COMMAND="foo bar -r" AUTO_COMMAND_START=11099