Add plugin to show notification

This commit is contained in:
Arun Prakash Jana 2019-12-12 00:56:39 +05:30
parent b64df85d23
commit f95ee54870
No known key found for this signature in database
GPG key ID: A75979F35C080412
3 changed files with 28 additions and 6 deletions

View file

@ -56,12 +56,12 @@ Add to that an awesome [Wiki](https://github.com/jarun/nnn/wiki)!
- Detailed file information - Detailed file information
- Media information (using plugin) - Media information (using plugin)
- Convenience - Convenience
- Notification on cp, mv, rm completion (needs ntfy)
- Run plugins and commands with custom keybinds - Run plugins and commands with custom keybinds
- FreeDesktop compliant trash (needs trash-cli) - FreeDesktop compliant trash (needs trash-cli)
- Cross-dir file/all/range selection - Cross-dir file/all/range selection
- Batch renamer (feature-limited) for selection or dir - Batch renamer (feature-limited) for selection or dir
- Copy (as), move (as), delete, archive, link selection - Copy (as), move (as), delete, archive, link selection
- Notification on cp, mv, rm completion
- Create (with parents), rename, duplicate (anywhere) files and dirs - Create (with parents), rename, duplicate (anywhere) files and dirs
- Launch GUI apps, run commands, execute file, spawn a shell - Launch GUI apps, run commands, execute file, spawn a shell
- Hovered file set as `$nnn` at prompt and spawned shell - Hovered file set as `$nnn` at prompt and spawned shell
@ -101,7 +101,6 @@ A curses library with wide char support (e.g. ncursesw), libreadline (`make O_NO
| archivemount, fusermount(3) | optional | mount, unmount archives | | archivemount, fusermount(3) | optional | mount, unmount archives |
| sshfs, [rclone](https://rclone.org/), fusermount(3) | optional | mount, unmount remotes | | sshfs, [rclone](https://rclone.org/), fusermount(3) | optional | mount, unmount remotes |
| trash-cli | optional | trash files (default action: rm) | | trash-cli | optional | trash files (default action: rm) |
| [ntfy](https://github.com/dschep/ntfy) | optional | operation completion notification |
| vlock (Linux), bashlock (macOS), lock(1) (BSD) | optional | terminal locker (fallback: [cmatrix](https://github.com/abishekvashok/cmatrix)) | | vlock (Linux), bashlock (macOS), lock(1) (BSD) | optional | terminal locker (fallback: [cmatrix](https://github.com/abishekvashok/cmatrix)) |
| advcpmv (Linux) ([integration](https://github.com/jarun/nnn/wiki/Advanced-use-cases#show-cp-mv-progress)) | optional | copy, move progress | | advcpmv (Linux) ([integration](https://github.com/jarun/nnn/wiki/Advanced-use-cases#show-cp-mv-progress)) | optional | copy, move progress |
| `$VISUAL` (else `$EDITOR`), `$PAGER`, `$SHELL` | optional | fallback vi, less, sh | | `$VISUAL` (else `$EDITOR`), `$PAGER`, `$SHELL` | optional | fallback vi, less, sh |

20
plugins/.notify Executable file
View file

@ -0,0 +1,20 @@
#!/usr/bin/env sh
# Description: Show a notification
#
# Details: nnn invokes this plugin to show notification when a cp/mv/rm operation is complete.
#
# Requires: notify-send (Ubuntu)/ntfy (https://github.com/dschep/ntfy)/osascript (macOS)
#
# Shell: POSIX compliant
# Author: Anna Arad
OS="$(uname)"
if which notify-send >/dev/null 2>&1; then
notify-send nnn "Done!"
elif [ "$OS" = "Darwin" ]; then
osascript -e 'display notification "Done!" with title "nnn"'
elif which ntfy >/dev/null 2>&1; then
ntfy -t nnn send "Done!"
fi

View file

@ -138,7 +138,7 @@
#define CTX_MAX 4 #define CTX_MAX 4
#define DOT_FILTER_LEN 7 #define DOT_FILTER_LEN 7
#define ASCII_MAX 128 #define ASCII_MAX 128
#define EXEC_ARGS_MAX 10 #define EXEC_ARGS_MAX 8
#define SCROLLOFF 3 #define SCROLLOFF 3
#define MIN_DISPLAY_COLS 10 #define MIN_DISPLAY_COLS 10
#define LONG_SIZE sizeof(ulong) #define LONG_SIZE sizeof(ulong)
@ -379,6 +379,7 @@ static bool g_plinit = FALSE;
#define UTIL_SH 14 #define UTIL_SH 14
#define UTIL_FZF 15 #define UTIL_FZF 15
#define UTIL_FZY 16 #define UTIL_FZY 16
#define UTIL_NOTIFY 17
/* Utilities to open files, run actions */ /* Utilities to open files, run actions */
static char * const utils[] = { static char * const utils[] = {
@ -411,6 +412,7 @@ static char * const utils[] = {
"sh", "sh",
"fzf", "fzf",
"fzy", "fzy",
".notify",
}; };
/* Common strings */ /* Common strings */
@ -4445,7 +4447,7 @@ nochange:
/* If open file is disabled on right arrow or `l`, return */ /* If open file is disabled on right arrow or `l`, return */
if (cfg.nonavopen && sel == SEL_NAV_IN) if (cfg.nonavopen && sel == SEL_NAV_IN)
continue; goto nochange;
/* Handle plugin selection mode */ /* Handle plugin selection mode */
if (cfg.runplugin) { if (cfg.runplugin) {
@ -4972,8 +4974,9 @@ nochange:
if (!cpmvrm_selection(sel, path, &presel)) if (!cpmvrm_selection(sel, path, &presel))
goto nochange; goto nochange;
spawn("ntfy -l CRITICAL -t nnn send Done!", /* Show notification on operation complete */
NULL, NULL, NULL, F_NOWAIT | F_NOTRACE | F_MULTI); mkpath(plugindir, utils[UTIL_NOTIFY], newpath);
spawn(newpath, NULL, NULL, NULL, F_NOWAIT | F_NOTRACE);
if (ndents) if (ndents)
copycurname(); copycurname();