Compare commits
25 commits
Author | SHA1 | Date | |
---|---|---|---|
f6c1f7fa35 | |||
86deef4ded | |||
81f5161390 | |||
e9ca099379 | |||
0a2b2f4601 | |||
8a328a37bd | |||
63f70f3c33 | |||
|
27c07dddb4 | ||
|
76a527a66b | ||
|
a79a412f3a | ||
|
837b81de92 | ||
|
6e5a54c5b5 | ||
|
43dbc4eb56 | ||
|
055a5fa8ae | ||
|
d41c04f778 | ||
|
0e4ed6b3c5 | ||
|
452eee9454 | ||
|
4eb63b7c1f | ||
|
8d61376a95 | ||
|
a663a08bca | ||
|
f405233080 | ||
|
2c0059707f | ||
|
f4766d6981 | ||
|
f4afef6fa9 | ||
|
22b2c61ed1 |
5 changed files with 67 additions and 39 deletions
12
CHANGELOG.md
12
CHANGELOG.md
|
@ -1,6 +1,18 @@
|
||||||
Changelog for zsh-auto-notify
|
Changelog for zsh-auto-notify
|
||||||
=============================
|
=============================
|
||||||
|
|
||||||
|
0.10.2
|
||||||
|
------
|
||||||
|
* Use preferable array argument expansion for flexible parameters
|
||||||
|
|
||||||
|
0.10.1
|
||||||
|
------
|
||||||
|
* Fix regression where not setting icon on Linux would cause issues (#59 #58)
|
||||||
|
|
||||||
|
0.10.0
|
||||||
|
-----
|
||||||
|
* Allow specifying an icon with notify-send backends
|
||||||
|
|
||||||
0.8.0
|
0.8.0
|
||||||
-----
|
-----
|
||||||
* Change notify-send application title to `zsh`
|
* Change notify-send application title to `zsh`
|
||||||
|
|
11
README.rst
11
README.rst
|
@ -162,6 +162,17 @@ then all the values in ``AUTO_NOTIFY_IGNORE`` are not used.
|
||||||
|
|
||||||
export AUTO_NOTIFY_WHITELIST=("apt-get" "docker")
|
export AUTO_NOTIFY_WHITELIST=("apt-get" "docker")
|
||||||
|
|
||||||
|
**Adding an icon - Linux**
|
||||||
|
|
||||||
|
If you wish to have an icon displayed on command success and/or failure, you can do so by defining the environmental variables ``AUTO_NOTIFY_ICON_SUCCESS`` and ``AUTO_NOTIFY_ICON_FAILURE`` respectively.
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
export AUTO_NOTIFY_ICON_SUCCESS=/path/to/success/icon.png
|
||||||
|
export AUTO_NOTIFY_ICON_FAILURE=/path/to/failure/icon.png
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Temporarily Disabling Notifications
|
Temporarily Disabling Notifications
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export AUTO_NOTIFY_VERSION="0.8.1"
|
export AUTO_NOTIFY_VERSION="0.10.2"
|
||||||
|
|
||||||
# Time it takes for a notification to expire
|
# Time it takes for a notification to expire
|
||||||
[[ -z "$AUTO_NOTIFY_EXPIRE_TIME" ]] &&
|
[[ -z "$AUTO_NOTIFY_EXPIRE_TIME" ]] &&
|
||||||
|
@ -6,6 +6,10 @@ export AUTO_NOTIFY_VERSION="0.8.1"
|
||||||
# Threshold in seconds for when to automatically show a notification
|
# Threshold in seconds for when to automatically show a notification
|
||||||
[[ -z "$AUTO_NOTIFY_THRESHOLD" ]] &&
|
[[ -z "$AUTO_NOTIFY_THRESHOLD" ]] &&
|
||||||
export AUTO_NOTIFY_THRESHOLD=10
|
export AUTO_NOTIFY_THRESHOLD=10
|
||||||
|
|
||||||
|
[[ -z "$AUTO_NOTIFY_PUBLISH" ]] &&
|
||||||
|
export AUTO_NOTIFY_PUBLISH="zsh_events"
|
||||||
|
|
||||||
# List of commands/programs to ignore sending notifications for
|
# List of commands/programs to ignore sending notifications for
|
||||||
[[ -z "$AUTO_NOTIFY_IGNORE" ]] &&
|
[[ -z "$AUTO_NOTIFY_IGNORE" ]] &&
|
||||||
export AUTO_NOTIFY_IGNORE=(
|
export AUTO_NOTIFY_IGNORE=(
|
||||||
|
@ -40,33 +44,30 @@ function _auto_notify_message() {
|
||||||
local exit_code="$3"
|
local exit_code="$3"
|
||||||
local platform="$(uname)"
|
local platform="$(uname)"
|
||||||
# Run using echo -e in order to make sure notify-send picks up new line
|
# Run using echo -e in order to make sure notify-send picks up new line
|
||||||
local DEFAULT_TITLE="\"%command\" Completed"
|
local DEFAULT_TITLE="ZSH: '%command' finished"
|
||||||
local DEFAULT_BODY="$(echo -e "Total time: %elapsed seconds\nExit code: %exit_code")"
|
local DEFAULT_BODY="$(echo -e "Time: %elapsed seconds elapsed\nExit code: %exit_code")"
|
||||||
|
local DEFAULT_PUBLISH="zsh_events"
|
||||||
|
|
||||||
local title="${AUTO_NOTIFY_TITLE:-$DEFAULT_TITLE}"
|
local title="${AUTO_NOTIFY_TITLE:-$DEFAULT_TITLE}"
|
||||||
local text="${AUTO_NOTIFY_BODY:-$DEFAULT_BODY}"
|
local text="${AUTO_NOTIFY_BODY:-$DEFAULT_BODY}"
|
||||||
|
local publish="${AUTO_NOTIFY_PUBLISH:-$DEFAULT_PUBLISH}"
|
||||||
|
|
||||||
title="$(_auto_notify_format "$title" "$command" "$elapsed" "$exit_code")"
|
title="$(_auto_notify_format "$title" "$command" "$elapsed" "$exit_code")"
|
||||||
body="$(_auto_notify_format "$text" "$command" "$elapsed" "$exit_code")"
|
body="$(_auto_notify_format "$text" "$command" "$elapsed" "$exit_code")"
|
||||||
|
|
||||||
if [[ "$platform" == "Linux" ]]; then
|
local urgency="3"
|
||||||
local urgency="normal"
|
local icon=${AUTO_NOTIFY_ICON_SUCCESS:-""}
|
||||||
local transient="--hint=int:transient:1"
|
# Exit code 130 is returned when a process is terminated with SIGINT.
|
||||||
if [[ "$exit_code" != "0" ]]; then
|
# Since the user is already interacting with the program, there is no
|
||||||
urgency="critical"
|
# need to make the notification persistent.
|
||||||
transient=""
|
if [[ "$exit_code" != "0" ]] && [[ "$exit_code" != "130" ]]; then
|
||||||
fi
|
urgency="4"
|
||||||
notify-send "$title" "$body" --app-name=zsh $transient "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME"
|
icon=${AUTO_NOTIFY_ICON_FAILURE:-""}
|
||||||
elif [[ "$platform" == "Darwin" ]]; then
|
|
||||||
osascript \
|
|
||||||
-e 'on run argv' \
|
|
||||||
-e 'display notification (item 1 of argv) with title (item 2 of argv)' \
|
|
||||||
-e 'end run' \
|
|
||||||
"$body" "$title"
|
|
||||||
else
|
|
||||||
printf "Unknown platform for sending notifications: $platform\n"
|
|
||||||
printf "Please post an issue on gitub.com/MichaelAquilina/zsh-auto-notify/issues/\n"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local arguments=("--title='$title'" "--priority=$urgency" $publish "$body")
|
||||||
|
|
||||||
|
ntfy publish -q ${arguments[@]}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _is_auto_notify_ignored() {
|
function _is_auto_notify_ignored() {
|
||||||
|
@ -77,6 +78,12 @@ 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/^ *//')"
|
||||||
|
|
||||||
|
# If the command is being run over SSH, then ignore it
|
||||||
|
if [[ -n ${SSH_CLIENT-} || -n ${SSH_TTY-} || -n ${SSH_CONNECTION-} ]]; then
|
||||||
|
print "yes"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
# Remove sudo prefix from command if detected
|
# Remove sudo prefix from command if detected
|
||||||
if [[ "$target_command" == "sudo "* ]]; then
|
if [[ "$target_command" == "sudo "* ]]; then
|
||||||
target_command="${target_command/sudo /}"
|
target_command="${target_command/sudo /}"
|
||||||
|
@ -159,11 +166,4 @@ function enable_auto_notify() {
|
||||||
|
|
||||||
_auto_notify_reset_tracking
|
_auto_notify_reset_tracking
|
||||||
|
|
||||||
|
|
||||||
platform="$(uname)"
|
|
||||||
if [[ "$platform" == "Linux" ]] && ! type notify-send > /dev/null; then
|
|
||||||
printf "'notify-send' must be installed for zsh-auto-notify to work\n"
|
|
||||||
printf "Please install it with your relevant package manager\n"
|
|
||||||
else
|
|
||||||
enable_auto_notify
|
enable_auto_notify
|
||||||
fi
|
|
||||||
|
|
|
@ -89,7 +89,22 @@
|
||||||
assert "$lines[1]" same_as 'Notification Title: "f bar -r" Completed'
|
assert "$lines[1]" same_as 'Notification Title: "f bar -r" Completed'
|
||||||
assert "$lines[2]" same_as "Notification Body: Total time: 20 seconds"
|
assert "$lines[2]" same_as "Notification Body: Total time: 20 seconds"
|
||||||
assert "$lines[3]" same_as "Exit code: 0"
|
assert "$lines[3]" same_as "Exit code: 0"
|
||||||
assert "$lines[4]" same_as "--app-name=zsh --transient --urgency=normal --expire-time=15000"
|
assert "$lines[4]" same_as "--app-name=zsh --hint=int:transient:1 --urgency=normal --expire-time=15000"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'auto-notify-send sends notification and icon on Linux on success' {
|
||||||
|
AUTO_COMMAND="f bar -r"
|
||||||
|
AUTO_COMMAND_FULL="foo bar -r"
|
||||||
|
AUTO_COMMAND_START=11080
|
||||||
|
AUTO_NOTIFY_EXPIRE_TIME=15000
|
||||||
|
AUTO_NOTIFY_ICON_SUCCESS=/path/to/success/icon.png
|
||||||
|
run _auto_notify_send
|
||||||
|
|
||||||
|
assert $state equals 0
|
||||||
|
assert "$lines[1]" same_as 'Notification Title: "f bar -r" Completed'
|
||||||
|
assert "$lines[2]" same_as "Notification Body: Total time: 20 seconds"
|
||||||
|
assert "$lines[3]" same_as "Exit code: 0"
|
||||||
|
assert "$lines[4]" same_as "--app-name=zsh --hint=int:transient:1 --urgency=normal --expire-time=15000 --icon=/path/to/success/icon.png"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test 'auto-notify-send sends notification on macOS' {
|
@test 'auto-notify-send sends notification on macOS' {
|
||||||
|
|
|
@ -10,16 +10,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@test 'version exported' {
|
|
||||||
git_version="$(git tag --list | sort -V | tail -1)"
|
|
||||||
git tag --list
|
|
||||||
|
|
||||||
load "../auto-notify.plugin.zsh"
|
|
||||||
|
|
||||||
assert "$AUTO_NOTIFY_VERSION" is_not_empty
|
|
||||||
assert "$AUTO_NOTIFY_VERSION" same_as "$git_version"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test 'print warning if notify-send is not installed' {
|
@test 'print warning if notify-send is not installed' {
|
||||||
function type {
|
function type {
|
||||||
return 1
|
return 1
|
||||||
|
|
Loading…
Add table
Reference in a new issue