diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index cea50d6..f7a728b 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -1,8 +1,14 @@ export AUTO_NOTIFY_VERSION="0.1.0" +# Command that the user has executed AUTO_COMMAND="" +# Full command that the user has executed after alias expansion +AUTO_COMMAND_FULL="" +# Command start time in seconds since epoch AUTO_COMMAND_START=0 +# Threshold for when to automatically show a notification AUTO_NOTIFY_THRESHOLD=5 +# List of commands/programs to ignore sending notifications for AUTO_NOTIFY_IGNORE=("vim" "nvim" "emacs" "less" "more" "man") autoload -Uz add-zsh-hook @@ -29,7 +35,7 @@ function _is_auto_notify_ignored() { function _auto_notify_send() { local current="$(date +"%s")" - if [[ "$(_is_auto_notify_ignored "$AUTO_COMMAND")" == "yes" ]]; then + if [[ "$(_is_auto_notify_ignored "$AUTO_COMMAND_FULL")" == "yes" ]]; then return fi @@ -42,6 +48,7 @@ function _auto_notify_send() { function _auto_notify_track() { AUTO_COMMAND="$1" + AUTO_COMMAND_FULL="$2" AUTO_COMMAND_START="$(date +"%s")" } diff --git a/tests/test_auto_notify.zunit b/tests/test_auto_notify.zunit index 6fe8c76..798a4f5 100644 --- a/tests/test_auto_notify.zunit +++ b/tests/test_auto_notify.zunit @@ -38,6 +38,7 @@ @test 'auto-notify-send does not send notification for short task' { AUTO_COMMAND="foo bar -r" + AUTO_COMMAND_FULL="foo bar -r" AUTO_COMMAND_START=11099 run _auto_notify_send @@ -47,7 +48,8 @@ @test 'auto-notify-send does not send notification for ignored commands' { for command in $AUTO_NOTIFY_IGNORE; do - AUTO_COMMAND="$command bar -r" + AUTO_COMMAND="somealias bar -r" + AUTO_COMMAND_FULL="$command bar -r" AUTO_COMMAND_START=11000 run _auto_notify_send @@ -57,11 +59,12 @@ } @test 'auto-notify-send sends notification' { - AUTO_COMMAND="foo bar -r" + AUTO_COMMAND="f bar -r" + AUTO_COMMAND_FULL="foo bar -r" AUTO_COMMAND_START=11080 run _auto_notify_send assert $state equals 0 - assert "$lines[1]" same_as 'Notification: "foo bar -r" has completed' + assert "$lines[1]" same_as 'Notification: "f bar -r" has completed' assert "$lines[2]" same_as "(Total time: 20 seconds)" }