commit
8ab1d0d8d2
4 changed files with 70 additions and 8 deletions
|
@ -1,6 +1,10 @@
|
||||||
Changelog for zsh-auto-notify
|
Changelog for zsh-auto-notify
|
||||||
=============================
|
=============================
|
||||||
|
|
||||||
|
0.7.0
|
||||||
|
-----
|
||||||
|
* Allow alternate `AUTO_NOTIFY_WHITELIST` for specifying commands to allow
|
||||||
|
|
||||||
0.6.0
|
0.6.0
|
||||||
-----
|
-----
|
||||||
* Display warning and disable auto-notify if notify-send is not installed (Linux only)
|
* Display warning and disable auto-notify if notify-send is not installed (Linux only)
|
||||||
|
|
11
README.rst
11
README.rst
|
@ -143,6 +143,17 @@ a new array.
|
||||||
# redefine what is ignored by auto-notify
|
# redefine what is ignored by auto-notify
|
||||||
export AUTO_NOTIFY_IGNORE=("docker" "man" "sleep")
|
export AUTO_NOTIFY_IGNORE=("docker" "man" "sleep")
|
||||||
|
|
||||||
|
**Using a Whitelist to ignore commands**
|
||||||
|
|
||||||
|
If you wish to use a whitelist approach instead of the default blacklist approach used by ``AUTO_NOTIFY_IGNORE``,
|
||||||
|
you can do so by defining the environment variable ``AUTO_NOTIFY_WHITELIST`` with the elements you wish to
|
||||||
|
allow ``auto-notify`` to track and send notifications for. NOTE: If ``AUTO_NOTIFY_WHITELIST`` is defined,
|
||||||
|
then all the values in ``AUTO_NOTIFY_IGNORE`` are not used.
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
export AUTO_NOTIFY_WHITELIST=("apt-get" "docker")
|
||||||
|
|
||||||
Temporarily Disabling Notifications
|
Temporarily Disabling Notifications
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export AUTO_NOTIFY_VERSION="0.6.0"
|
export AUTO_NOTIFY_VERSION="0.7.0"
|
||||||
|
|
||||||
# Time it takes for a notification to expire
|
# Time it takes for a notification to expire
|
||||||
export AUTO_NOTIFY_EXPIRE_TIME=8000
|
export AUTO_NOTIFY_EXPIRE_TIME=8000
|
||||||
|
@ -61,13 +61,33 @@ function _is_auto_notify_ignored() {
|
||||||
# Remove leading whitespace
|
# Remove leading whitespace
|
||||||
target_command="$(echo "$target_command" | sed -e 's/^ *//')"
|
target_command="$(echo "$target_command" | sed -e 's/^ *//')"
|
||||||
|
|
||||||
for ignore in $AUTO_NOTIFY_IGNORE; do
|
# Remove sudo prefix from command if detected
|
||||||
if [[ "$target_command" == "$ignore"* ]]; then
|
if [[ "$target_command" == "sudo "* ]]; then
|
||||||
print "yes"
|
target_command="${target_command/sudo /}"
|
||||||
return
|
fi
|
||||||
fi
|
|
||||||
done
|
# If AUTO_NOTIFY_WHITELIST is defined, then auto-notify will ignore
|
||||||
print "no"
|
# any item not defined in the white list
|
||||||
|
# Otherwise - the alternative (default) approach is used where the
|
||||||
|
# AUTO_NOTIFY_IGNORE blacklist is used to ignore commands
|
||||||
|
|
||||||
|
if [[ -n "$AUTO_NOTIFY_WHITELIST" ]]; then
|
||||||
|
for allowed in $AUTO_NOTIFY_WHITELIST; do
|
||||||
|
if [[ "$target_command" == "$allowed"* ]]; then
|
||||||
|
print "no"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
print "yes"
|
||||||
|
else
|
||||||
|
for ignore in $AUTO_NOTIFY_IGNORE; do
|
||||||
|
if [[ "$target_command" == "$ignore"* ]]; then
|
||||||
|
print "yes"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
print "no"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function _auto_notify_send() {
|
function _auto_notify_send() {
|
||||||
|
|
|
@ -33,3 +33,30 @@
|
||||||
assert $state equals 0
|
assert $state equals 0
|
||||||
assert "$output" same_as "yes"
|
assert "$output" same_as "yes"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test 'is_auto_notify_ignored - AUTO_NOTIFY_WHITELIST disallowed' {
|
||||||
|
AUTO_NOTIFY_WHITELIST="foobar"
|
||||||
|
|
||||||
|
run _is_auto_notify_ignored "boom baz"
|
||||||
|
|
||||||
|
assert $state equals 0
|
||||||
|
assert "$output" same_as "yes"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'is_auto_notify_ignored - AUTO_NOTIFY_WHITELIST allowed' {
|
||||||
|
AUTO_NOTIFY_WHITELIST="foobar"
|
||||||
|
|
||||||
|
run _is_auto_notify_ignored "foobar baz"
|
||||||
|
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue