]> Sergey Matveev's repositories - nnn.git/commitdiff
Add plugin to show notification
authorArun Prakash Jana <engineerarun@gmail.com>
Wed, 11 Dec 2019 19:26:39 +0000 (00:56 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Thu, 12 Dec 2019 01:54:22 +0000 (07:24 +0530)
README.md
plugins/.notify [new file with mode: 0755]
src/nnn.c

index 346e4e7047af58a70a2200313cba2f4674c37bd6..34ba51d14584487e10a3470b04a503869f2fd7ed 100644 (file)
--- a/README.md
+++ b/README.md
@@ -56,12 +56,12 @@ Add to that an awesome [Wiki](https://github.com/jarun/nnn/wiki)!
   - Detailed file information
   - Media information (using plugin)
 - Convenience
-  - Notification on cp, mv, rm completion (needs ntfy)
   - Run plugins and commands with custom keybinds
   - FreeDesktop compliant trash (needs trash-cli)
   - Cross-dir file/all/range selection
   - Batch renamer (feature-limited) for selection or dir
   - Copy (as), move (as), delete, archive, link selection
+  - Notification on cp, mv, rm completion
   - Create (with parents), rename, duplicate (anywhere) files and dirs
   - Launch GUI apps, run commands, execute file, spawn a 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 |
 | sshfs, [rclone](https://rclone.org/), fusermount(3) | optional | mount, unmount remotes |
 | 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)) |
 | 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 |
diff --git a/plugins/.notify b/plugins/.notify
new file mode 100755 (executable)
index 0000000..fe0e18a
--- /dev/null
@@ -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
index 1e25bf8ca51e34663c03f3045286dc51b7bcdae8..7500d01abb0602e90d15b2b82ca11271c87e5f96 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
 #define CTX_MAX 4
 #define DOT_FILTER_LEN 7
 #define ASCII_MAX 128
-#define EXEC_ARGS_MAX 10
+#define EXEC_ARGS_MAX 8
 #define SCROLLOFF 3
 #define MIN_DISPLAY_COLS 10
 #define LONG_SIZE sizeof(ulong)
@@ -379,6 +379,7 @@ static bool g_plinit = FALSE;
 #define UTIL_SH 14
 #define UTIL_FZF 15
 #define UTIL_FZY 16
+#define UTIL_NOTIFY 17
 
 /* Utilities to open files, run actions */
 static char * const utils[] = {
@@ -411,6 +412,7 @@ static char * const utils[] = {
        "sh",
        "fzf",
        "fzy",
+       ".notify",
 };
 
 /* Common strings */
@@ -4445,7 +4447,7 @@ nochange:
 
                                /* If open file is disabled on right arrow or `l`, return */
                                if (cfg.nonavopen && sel == SEL_NAV_IN)
-                                       continue;
+                                       goto nochange;
 
                                /* Handle plugin selection mode */
                                if (cfg.runplugin) {
@@ -4972,8 +4974,9 @@ nochange:
                        if (!cpmvrm_selection(sel, path, &presel))
                                goto nochange;
 
-                       spawn("ntfy -l CRITICAL -t nnn send Done!",
-                             NULL, NULL, NULL, F_NOWAIT | F_NOTRACE | F_MULTI);
+                       /* Show notification on operation complete */
+                       mkpath(plugindir, utils[UTIL_NOTIFY], newpath);
+                       spawn(newpath, NULL, NULL, NULL, F_NOWAIT | F_NOTRACE);
 
                        if (ndents)
                                copycurname();