From cbd4e2bcac46d92da471dbec2f098f01fb5bdb5b Mon Sep 17 00:00:00 2001 From: Michael Aquilina Date: Mon, 26 Aug 2019 12:25:43 +0100 Subject: [PATCH] Remove sudo prefix from command if detected --- auto-notify.plugin.zsh | 5 +++++ tests/test_is_auto_notify_ignored.zunit | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index 022d131..58820d6 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -61,6 +61,11 @@ function _is_auto_notify_ignored() { # Remove leading whitespace target_command="$(echo "$target_command" | sed -e 's/^ *//')" + # Remove sudo prefix from command if detected + if [[ "$target_command" == "sudo "* ]]; then + target_command="${target_command/sudo /}" + fi + # If AUTO_NOTIFY_WHITELIST is defined, then auto-notify will ignore # any item not defined in the white list # Otherwise - the alternative (default) approach is used where the diff --git a/tests/test_is_auto_notify_ignored.zunit b/tests/test_is_auto_notify_ignored.zunit index 8397482..cb4f4fa 100644 --- a/tests/test_is_auto_notify_ignored.zunit +++ b/tests/test_is_auto_notify_ignored.zunit @@ -51,3 +51,12 @@ assert $state equals 0 assert "$output" same_as "no" } + +@test 'is_auto_notify_ignored - AUTO_NOTIFY_WHITELIST allowed with sudo' { + AUTO_NOTIFY_WHITELIST="foobar" + + run _is_auto_notify_ignored "sudo foobar baz" + + assert $state equals 0 + assert "$output" same_as "no" +}