Check commands to ignore after alias expansion

This commit is contained in:
Michael Aquilina 2019-07-14 18:22:46 +01:00
parent fc92fa6951
commit 070eea8265
No known key found for this signature in database
GPG key ID: 636066730B056BD1
2 changed files with 14 additions and 4 deletions

View file

@ -1,8 +1,14 @@
export AUTO_NOTIFY_VERSION="0.1.0" export AUTO_NOTIFY_VERSION="0.1.0"
# Command that the user has executed
AUTO_COMMAND="" 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 AUTO_COMMAND_START=0
# Threshold for when to automatically show a notification
AUTO_NOTIFY_THRESHOLD=5 AUTO_NOTIFY_THRESHOLD=5
# List of commands/programs to ignore sending notifications for
AUTO_NOTIFY_IGNORE=("vim" "nvim" "emacs" "less" "more" "man") AUTO_NOTIFY_IGNORE=("vim" "nvim" "emacs" "less" "more" "man")
autoload -Uz add-zsh-hook autoload -Uz add-zsh-hook
@ -29,7 +35,7 @@ function _is_auto_notify_ignored() {
function _auto_notify_send() { function _auto_notify_send() {
local current="$(date +"%s")" local current="$(date +"%s")"
if [[ "$(_is_auto_notify_ignored "$AUTO_COMMAND")" == "yes" ]]; then if [[ "$(_is_auto_notify_ignored "$AUTO_COMMAND_FULL")" == "yes" ]]; then
return return
fi fi
@ -42,6 +48,7 @@ function _auto_notify_send() {
function _auto_notify_track() { function _auto_notify_track() {
AUTO_COMMAND="$1" AUTO_COMMAND="$1"
AUTO_COMMAND_FULL="$2"
AUTO_COMMAND_START="$(date +"%s")" AUTO_COMMAND_START="$(date +"%s")"
} }

View file

@ -38,6 +38,7 @@
@test 'auto-notify-send does not send notification for short task' { @test 'auto-notify-send does not send notification for short task' {
AUTO_COMMAND="foo bar -r" AUTO_COMMAND="foo bar -r"
AUTO_COMMAND_FULL="foo bar -r"
AUTO_COMMAND_START=11099 AUTO_COMMAND_START=11099
run _auto_notify_send run _auto_notify_send
@ -47,7 +48,8 @@
@test 'auto-notify-send does not send notification for ignored commands' { @test 'auto-notify-send does not send notification for ignored commands' {
for command in $AUTO_NOTIFY_IGNORE; do 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 AUTO_COMMAND_START=11000
run _auto_notify_send run _auto_notify_send
@ -57,11 +59,12 @@
} }
@test 'auto-notify-send sends notification' { @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 AUTO_COMMAND_START=11080
run _auto_notify_send run _auto_notify_send
assert $state equals 0 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)" assert "$lines[2]" same_as "(Total time: 20 seconds)"
} }