diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index 6194d34..1b7f87e 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -1,3 +1,5 @@ +export AUTO_NOTIFY_VERSION="0.1.0" + AUTO_COMMAND="" AUTO_COMMAND_START=0 AUTO_NOTIFY_THRESHOLD=5 @@ -24,7 +26,7 @@ function _is_auto_notify_ignored() { print "no" } -function _notify_command() { +function _auto_notify_send() { local current="$(date +"%s")" if [[ "$(_is_auto_notify_ignored "$AUTO_COMMAND")" == "yes" ]]; then @@ -38,10 +40,11 @@ function _notify_command() { fi } -function _track_command() { +function _auto_notify_track() { AUTO_COMMAND="$1" AUTO_COMMAND_START="$(date +"%s")" } -add-zsh-hook preexec _track_command -add-zsh-hook precmd _notify_command +autoload -U add-zsh-hook +add-zsh-hook preexec _auto_notify_track +add-zsh-hook precmd _auto_notify_send diff --git a/tests/test_auto_notify.zunit b/tests/test_auto_notify.zunit new file mode 100644 index 0000000..a3dfbcc --- /dev/null +++ b/tests/test_auto_notify.zunit @@ -0,0 +1,14 @@ +#!/usr/bin/env zunit + +@setup { + load "../auto-notify.plugin.zsh" +} + +@test 'version exported' { + assert "$AUTO_NOTIFY_VERSION" is_not_empty +} + +@test 'hook functions are loaded by default' { + assert '_auto_notify_track' in $preexec_functions + assert '_auto_notify_send' in $precmd_functions +}