Compare commits

..

39 commits

Author SHA1 Message Date
f6c1f7fa35 auto-notify.plugin.zsh aktualisiert 2024-09-16 22:58:04 +02:00
86deef4ded auto-notify.plugin.zsh aktualisiert 2024-09-16 20:39:21 +02:00
81f5161390 auto-notify.plugin.zsh aktualisiert 2024-09-16 20:37:27 +02:00
e9ca099379 auto-notify.plugin.zsh aktualisiert 2024-09-16 20:35:51 +02:00
0a2b2f4601 auto-notify.plugin.zsh aktualisiert 2024-09-16 20:30:57 +02:00
8a328a37bd auto-notify.plugin.zsh aktualisiert 2024-09-16 20:30:05 +02:00
63f70f3c33 auto-notify.plugin.zsh aktualisiert
Changed Plugin to use ntfy instead of notify-send, to send events to phone.

Signed-off-by: eeleater <nikolasweger@googlemail.com>
2024-09-16 20:20:39 +02:00
Michael Aquilina
27c07dddb4
Merge pull request #63 from Grafcube/ignore-130
Treat code 130 as success
2024-07-08 16:43:31 +01:00
Grafcube
76a527a66b
Add a comment explaining why 130 is treated as success 2024-07-08 19:53:44 +05:30
Grafcube
a79a412f3a
Treat code 130 as success 2024-06-16 00:21:26 +05:30
Michael Aquilina
837b81de92
bump version to 0.10.2 2024-05-13 11:12:38 +01:00
Michael Aquilina
6e5a54c5b5
use array argument expansion 2024-05-13 11:11:51 +01:00
Michael Aquilina
43dbc4eb56
bump version to 0.10.1 2024-05-13 10:54:40 +01:00
Michael Aquilina
055a5fa8ae
Merge pull request #61 from MichaelAquilina/fix/bad-icon-path
fix: correctly omit --icon from notify-send when not set
2024-05-13 11:53:56 +02:00
Michael Aquilina
d41c04f778
remove flakey test 2024-05-13 10:51:50 +01:00
Michael Aquilina
0e4ed6b3c5
fix: correctly omit --icon from notify-send when not set 2024-05-13 10:48:41 +01:00
Michael Aquilina
452eee9454
bump version to 0.10.0 2024-04-24 13:25:36 +01:00
Michael Aquilina
4eb63b7c1f
Merge pull request #56 from CaderIdris/add-icon-support
Add Icon Support to Linux
2024-04-24 13:24:21 +01:00
61825162+CaderIdris@users.noreply.github.com
8d61376a95
Fixed version number
Modified: Version number so ci tests pass
2024-04-23 12:51:59 +01:00
61825162+CaderIdris@users.noreply.github.com
a663a08bca
Bugfix: Order of arguments passed unit tests but caused invalid parsing
of expire time argument

Modified: How icon argument is called
2024-04-23 12:04:05 +01:00
61825162+CaderIdris@users.noreply.github.com
f405233080
Added tests and updated README
Added: Test for running notify-send when declaring success icon
Added: Config information to README

Note: With the way the tests are currently structured, I couldn't find a
way to test the failure icon. I'm not an expert in zunit so there may
be a way that I can't find
2024-04-23 11:50:34 +01:00
61825162+CaderIdris@users.noreply.github.com
2c0059707f
Added icon support for linux
Added: AUTO_NOTIFY_ICON_SUCCESS environmental variable, represents path
to icon for notify-send to display on command success
Added: AUTO_NOTIFY_ICON_FAILURE environmental variable, represents path
to icon for notify-send to display on command failure
Added: --icon option when icon path is present for notify-send, no
additional argument added if environmental variable not specified
Modified: Version number to pass test
2024-04-23 11:15:09 +01:00
Michael Aquilina
f4766d6981
Merge pull request #53 from NoUseFreak/patch-1
Mute notifications over ssh
2024-02-08 15:33:32 +00:00
Dries De Peuter
f4afef6fa9
fix: mute notifications over ssh 2023-12-27 23:01:21 +01:00
Michael Aquilina
22b2c61ed1
fix: transient test case 2023-06-02 14:01:43 +01:00
Michael Aquilina
9b6bc124f0
fix: backwards compatible transient flag 2023-06-02 13:55:02 +01:00
Michael Aquilina
dad1e61c71
Merge pull request #45 from Grafcube/fix-transient
Fix transient argument
2023-05-11 15:24:59 +01:00
Michael Aquilina
993f5de86e
fix: update tests to include --transient flag 2023-05-11 15:23:14 +01:00
Michael Aquilina
00951ac085
build: update docker job image and install libnotify-bin 2023-05-11 15:15:01 +01:00
Grafcube
5a50536e59
Fix transient argument
The transient variable must not be quoted. Otherwise the command fails
with `Invalid number of options.` for unsuccessful error codes.
2023-05-11 17:02:14 +05:30
Michael Aquilina
71e8da986f
Merge pull request #41 from Grafcube/transient-on-success
Make notifications transient if successful
2023-04-27 16:47:46 +01:00
Grafcube
9a9f8f21bb
Quote transient 2023-04-27 21:12:11 +05:30
Grafcube
8418a6e3b2
Make notifications transient if successful 2023-04-04 12:38:28 +05:30
Michael Aquilina
1f64cb6544
Merge pull request #38 from brendanfalk/fig
Add Fig as an installation method to the README
2022-06-29 09:42:29 +01:00
Brendan Falk
b15ae822e6
Update README.rst 2022-06-28 10:44:09 -07:00
Brendan Falk
5060c0757f
Add Fig as an installation method to the README 2022-06-27 17:12:45 -07:00
Michael Aquilina
30c3c60939
Merge pull request #36 from spikespaz/master
Fix the environment variables being reset upon sourcing the plugin
2022-02-21 10:28:22 +00:00
Jacob Birkett
86849ede2a Fix config being overwritten when source 2022-01-27 18:05:20 -07:00
Michael Aquilina
fb38802d33
Merge pull request #25 from MichaelAquilina/develop
Release 0.8.0
2019-09-06 10:00:50 +01:00
6 changed files with 98 additions and 44 deletions

View file

@ -6,7 +6,7 @@ test: &test
- checkout - checkout
- run: - run:
name: Install Dependencies name: Install Dependencies
command: apt-get update && apt-get install -y curl git ncurses-bin command: apt-get update && apt-get install -y curl git ncurses-bin libnotify-bin
- run: - run:
name: Download requirements name: Download requirements
command: | command: |
@ -25,7 +25,7 @@ test: &test
jobs: jobs:
lint: lint:
docker: docker:
- image: "python:3.7-stretch" - image: "python:3.11"
steps: steps:
- checkout - checkout
- run: - run:

View file

@ -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`

View file

@ -64,6 +64,14 @@ Zgen_
zgen load "MichaelAquilina/zsh-auto-notify" zgen load "MichaelAquilina/zsh-auto-notify"
Fig_
Install ``zsh-auto-notify`` with Fig in just one click.
.. image:: https://fig.io/badges/install-with-fig.svg
:target: https://fig.io/plugins/other/zsh-auto-notify_MichaelAquilina
:alt: Install with Fig
oh-my-zsh_ oh-my-zsh_
Copy this repository to ``$ZSH_CUSTOM/custom/plugins``, where ``$ZSH_CUSTOM`` Copy this repository to ``$ZSH_CUSTOM/custom/plugins``, where ``$ZSH_CUSTOM``
@ -154,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
----------------------------------- -----------------------------------
@ -202,6 +221,8 @@ NOTE: It is required that you use a minimum zunit version of 0.8.2
.. _ZGen: https://github.com/tarjoilija/zgen .. _ZGen: https://github.com/tarjoilija/zgen
.. _Fig: https://fig.io
.. _oh-my-zsh: https://github.com/robbyrussell/oh-my-zsh .. _oh-my-zsh: https://github.com/robbyrussell/oh-my-zsh
.. |GPLv3| image:: https://img.shields.io/badge/License-GPL%20v3-blue.svg .. |GPLv3| image:: https://img.shields.io/badge/License-GPL%20v3-blue.svg

View file

@ -1,13 +1,31 @@
export AUTO_NOTIFY_VERSION="0.8.0" export AUTO_NOTIFY_VERSION="0.10.2"
# Time it takes for a notification to expire # Time it takes for a notification to expire
export AUTO_NOTIFY_EXPIRE_TIME=8000 [[ -z "$AUTO_NOTIFY_EXPIRE_TIME" ]] &&
export AUTO_NOTIFY_EXPIRE_TIME=8000
# Threshold in seconds for when to automatically show a notification # Threshold in seconds for when to automatically show a notification
export AUTO_NOTIFY_THRESHOLD=10 [[ -z "$AUTO_NOTIFY_THRESHOLD" ]] &&
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
export AUTO_NOTIFY_IGNORE=( [[ -z "$AUTO_NOTIFY_IGNORE" ]] &&
"vim" "nvim" "less" "more" "man" "tig" "watch" "git commit" "top" "htop" "ssh" "nano" export AUTO_NOTIFY_IGNORE=(
) 'vim'
'nvim'
'less'
'more'
'man'
'tig'
'watch'
'git commit'
'top'
'htop'
'ssh'
'nano'
)
function _auto_notify_format() { function _auto_notify_format() {
local MESSAGE="$1" local MESSAGE="$1"
@ -26,31 +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:-""}
if [[ "$exit_code" != "0" ]]; then # Exit code 130 is returned when a process is terminated with SIGINT.
urgency="critical" # Since the user is already interacting with the program, there is no
fi # need to make the notification persistent.
notify-send "$title" "$body" --app-name=zsh "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME" if [[ "$exit_code" != "0" ]] && [[ "$exit_code" != "130" ]]; then
elif [[ "$platform" == "Darwin" ]]; then urgency="4"
osascript \ icon=${AUTO_NOTIFY_ICON_FAILURE:-""}
-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() {
@ -61,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 /}"
@ -143,11 +166,4 @@ function enable_auto_notify() {
_auto_notify_reset_tracking _auto_notify_reset_tracking
enable_auto_notify
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
fi

View file

@ -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 --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' {

View file

@ -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