]> Sergey Matveev's repositories - nnn.git/commitdiff
Move nlaunch to plugins as launch
authorArun Prakash Jana <engineerarun@gmail.com>
Sun, 8 Dec 2019 19:04:53 +0000 (00:34 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sun, 8 Dec 2019 19:04:53 +0000 (00:34 +0530)
README.md
misc/nlaunch/README.md [deleted file]
misc/nlaunch/nlaunch [deleted file]
plugins/README.md
plugins/getplugs
plugins/launch [new file with mode: 0755]
plugins/nuke
src/nnn.c

index d6a5b470bcdfa921744ea34ebf7f623a41b31237..05e226e242531b49f1ea3ed3cf39827ae4bb3ebf 100644 (file)
--- a/README.md
+++ b/README.md
@@ -77,7 +77,7 @@ Add to that an awesome [Wiki](https://github.com/jarun/nnn/wiki)!
 1. Install the [utilities you may need](https://github.com/jarun/nnn#utility-dependencies) based on your regular workflows.
 2. Configure [cd on quit](https://github.com/jarun/nnn/wiki/Basic-use-cases#configure-cd-on-quit).
 3. Optionally open all text files in `$EDITOR` (fallback vi): `export NNN_USE_EDITOR=1`.
-4. For additional functionality [install plugins](https://github.com/jarun/nnn/tree/master/plugins#installing-plugins) and the GUI app launcher [`nlaunch`](https://github.com/jarun/nnn/tree/master/misc/nlaunch).
+4. For additional functionality [install plugins](https://github.com/jarun/nnn/tree/master/plugins#installing-plugins).
 
 Notes:
 
@@ -232,7 +232,7 @@ The list below is from the **dev branch**. Press <kbd>?</kbd> in `nnn` to see th
  MISC
          ! ^]  Shell      ;K :K xK  Execute plugin K
             C  Execute entry  R ^V  Pick plugin
-            U  Manage session    =  Launch
+            U  Manage session    =  Launch app
             c  Remote mount      u  Unmount
          ] ^P  Prompt/run cmd    L  Lock
 ```
diff --git a/misc/nlaunch/README.md b/misc/nlaunch/README.md
deleted file mode 100644 (file)
index 2b267ee..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-`nlaunch` is an independent POSIX-compliant GUI application launcher shell script. To use it with `nnn` you need to mark the file executable and drop it somewhere in your `$PATH`.
-
-It requires [`fzy`](https://github.com/jhawthorn/fzy) to show a fuzzy drop-down menu.
-
-To use `nlaunch` as an independent launcher add a keybind to open `nlaunch` in a terminal e.g.
-
-    xfce4-terminal -e nlaunch
diff --git a/misc/nlaunch/nlaunch b/misc/nlaunch/nlaunch
deleted file mode 100755 (executable)
index 123e62d..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/usr/bin/env sh
-
-# Description: Fuzzy find executables in $PATH and launch an application.
-#              stdin, stdout, stderr are suppressed so CLI utilities exit silently.
-#              Works as an independent app launcher.
-#
-#              Requires fzy.
-#
-#              Usage: nlaunch [delay]
-#                     delay is in seconds, if omitted nlaunch waits for 1 sec
-#
-# Shell: POSIX compliant
-# Author: Arun Prakash Jana
-
-IFS=':'
-
-get_selection() {
-    ls -H $PATH | sort | fzy
-}
-
-if selection=$( get_selection ); then
-    setsid "$selection" 2>/dev/null 1>/dev/null &
-
-    if ! [ -z "$1" ]; then
-        sleep "$1"
-    else
-        sleep 1
-    fi
-fi
index 094238b7131aa6739d0cc8ad7216fa8420cc5df1..1906df7ead67db88f4c79b11c6e83055e5da0339 100644 (file)
@@ -20,7 +20,7 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina
 | diffs | Diff for selection (limited to 2 for directories) | sh | vimdiff |
 | dragdrop | Drag/drop files from/into nnn | sh | [dragon](https://github.com/mwh/dragon) |
 | exetoggle | Toggle executable status of hovered file | sh | chmod |
-| fzcd | Change to the directory of a fuzzy-selected file/dir | sh | fzy/fzf<br>(optional fd) |
+| fzcd | Change to the directory of a fuzzy-selected file/dir | sh | fzf/fzy<br>(optional fd) |
 | fzhist | Fuzzy-select a cmd from history, edit in `$EDITOR` and run | sh | fzy |
 | fzopen | Fuzzy find a file in dir subtree and edit or open | sh | fzy, xdg-open |
 | getplugs | Update plugins | sh | curl |
@@ -33,6 +33,7 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina
 | imgviu | View an image or images in dir in `$PAGER` | sh | [viu](https://github.com/atanunq/viu), less |
 | ipinfo | Fetch external IP address and whois information | sh | curl, whois |
 | kdeconnect | Send selected files to an Android device | sh | kdeconnect-cli |
+| launch | GUI application launcher | sh | fzf/fzy |
 | mediainf | Show media information | sh | mediainfo |
 | moclyrics | Show lyrics of the track playing in moc | sh | [ddgr](https://github.com/jarun/ddgr), [moc](http://moc.daper.net/) |
 | mocplay | Append (and/or play) selection/dir/file in moc | sh | [moc](http://moc.daper.net/) |
@@ -65,8 +66,6 @@ The following command installs all plugins:
 
 Plugins are installed to `${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins`. You can run the `getplugs` plugin later to update the plugins. It backs up earlier plugins.
 
-**NOTE:** `getplugs` also downloads the launcher `nlaunch` and tries to place it at `/usr/local/bin/` using `sudo`. If it fails you have to place `nlauch` manually somewhere in your `$PATH`.
-
 ## Executing plugins
 
 **Method 1:** Directly with <kbd>:key</kbd>:
index ff40360df0302efbda5d533410735ff95e452fb2..169c4aa40ffe0f0e124ccde43fa7faae203a988a 100755 (executable)
@@ -31,13 +31,13 @@ prompt () {
        fi
 }
 
-if [ "$(is_cmd_exists sudo)" -eq "0" ]; then
-    sucmd=sudo
-elif [ "$(is_cmd_exists doas)" -eq "0" ]; then
-    sucmd=doas
-else
-    sucmd=: # noop
-fi
+if [ "$(is_cmd_exists sudo)" -eq "0" ]; then
+    sucmd=sudo
+elif [ "$(is_cmd_exists doas)" -eq "0" ]; then
+    sucmd=doas
+else
+    sucmd=: # noop
+fi
 
 # backup any earlier plugins
 if [ -d "$PLUGIN_DIR" ]; then
@@ -65,5 +65,4 @@ for f in $(find . -maxdepth 1 \( ! -iname "." ! -iname "*.md" \)); do
 done
 cd ../.. || exit 1
 
-$sucmd mv -vf nnn-master/misc/nlaunch/nlaunch /usr/local/bin/
 rm -rf nnn-master/ master.tar.gz
diff --git a/plugins/launch b/plugins/launch
new file mode 100755 (executable)
index 0000000..f1b8a73
--- /dev/null
@@ -0,0 +1,42 @@
+#!/usr/bin/env sh
+
+# Description: Independent POSIX-compliant GUI application launcher.
+#              Fuzzy find executables in $PATH and launch an application.
+#              stdin, stdout, stderr are suppressed so CLI tools exit silently.
+#
+#              To configure launch as an independent app launcher add a keybind
+#              to open launch in a terminal e.g.,
+#
+#              xfce4-terminal -e "${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/launch
+#
+# Requires: fzf or fzy
+#
+# Usage: launch [delay]
+#        delay is in seconds, if omitted launch waits for 1 sec
+#
+# Integration with nnn: launch is installed with other plugins, nnn picks it up.
+#
+# Shell: POSIX compliant
+# Author: Arun Prakash Jana
+
+IFS=':'
+
+get_selection() {
+    if which fzf >/dev/null 2>&1; then
+        ls -H $PATH | sort | fzf
+    elif which fzy >/dev/null 2>&1; then
+        ls -H $PATH | sort | fzy
+    else
+        exit 1
+    fi
+}
+
+if selection=$( get_selection ); then
+    setsid "$selection" 2>/dev/null 1>/dev/null &
+
+    if ! [ -z "$1" ]; then
+        sleep "$1"
+    else
+        sleep 1
+    fi
+fi
index 1109894380f6aec07f1462762bd398178a191b3e..2bab939ab8fc42cca6a29a988e02b664c8768b60 100755 (executable)
@@ -1,11 +1,12 @@
 #!/usr/bin/env sh
 
 # #############################################################################
-# nuke: a sample script to play files in different apps by file type and mime
-# shell: POSIX compliant
-# usage: nuke filepath
+# Description: Sample script to play files in apps by file type or mime
 #
-# nnn integration:
+# Shell: POSIX compliant
+# Usage: nuke filepath
+#
+# Integration with nnn:
 #   1. Export the required config:
 #         export NNN_OPENER=/absolute/path/to/nuke
 #         # Otherwise, if nuke is in $PATH
@@ -14,7 +15,7 @@
 #         nnn -c
 #   3. nuke can use nnn plugins (e.g. mocplay is used for audio), $PATH is updated.
 #
-# details:
+# Details:
 #   Inspired by ranger's scope.sh, modified for usage with nnn.
 #
 #   Tries to play 'file' (1st argument) in the following order:
@@ -22,7 +23,7 @@
 #   ii. by mime (image, video, audio, pdf)
 #   iii. by mime (other file types)
 #
-# modification tips:
+# Modification tips:
 #   1. Invokes CLI utilities by default. Set GUI to 1 to enable GUI apps.
 #   2. PAGER is "less -R".
 #   3. Start GUI apps in bg to unblock. Redirect stdout and strerr if required.
@@ -32,7 +33,7 @@
 #
 #   Feel free to change the utilities to your favourites and add more mimes.
 #
-# defaults:
+# Defaults:
 #   By extension (only the enbaled ones):
 #      most archives: list with atool, bsdtar
 #      rar: list with unrar
index 4eb4112a72a5886a357e1e7d04a4db9a4257de66..c406d6e713335292b8d71d1c89806d39f25f1007 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -369,7 +369,7 @@ static bool g_plinit = FALSE;
 #define UTIL_TAR 4
 #define UTIL_LOCKER 5
 #define UTIL_CMATRIX 6
-#define UTIL_NLAUNCH 7
+#define UTIL_LAUNCH 7
 #define UTIL_SH_EXEC 8
 #define UTIL_ARCHIVEMOUNT 9
 #define UTIL_SSHFS 10
@@ -377,6 +377,8 @@ static bool g_plinit = FALSE;
 #define UTIL_VI 12
 #define UTIL_LESS 13
 #define UTIL_SH 14
+#define UTIL_FZF 15
+#define UTIL_FZY 16
 
 /* Utilities to open files, run actions */
 static char * const utils[] = {
@@ -399,7 +401,7 @@ static char * const utils[] = {
        "vlock",
 #endif
        "cmatrix",
-       "nlaunch",
+       "launch",
        "sh -c",
        "archivemount",
        "sshfs",
@@ -407,6 +409,8 @@ static char * const utils[] = {
        "vi",
        "less",
        "sh",
+       "fzf",
+       "fzy",
 };
 
 /* Common strings */
@@ -451,6 +455,7 @@ static char * const utils[] = {
 #define MSG_FEW_COLOUMNS 38
 #define MSG_REMOTE_OPTS 39
 #define MSG_RCLONE_DELAY 40
+#define MSG_APP_NAME 41
 
 static const char * const messages[] = {
        "no traversal",
@@ -493,7 +498,8 @@ static const char * const messages[] = {
        "entry exists",
        "too few columns!",
        "'s'shfs / 'r'clone?",
-       "may take a while, try refresh"
+       "may take a while, try refresh",
+       "app name: ",
 };
 
 /* Supported configuration environment variables */
@@ -2098,6 +2104,7 @@ static int filterentries(char *path)
                                if (len == 1)
                                        cur = oldcur;
                                goto end;
+                       case '=': // fallthrough /* Launch app */
                        case ':': // fallthrough /* Run plugin keys */
                        case ';': // fallthrough
                        case '?': /* Help and config key, '?' is an invalid regex */
@@ -3497,7 +3504,7 @@ static void show_help(const char *path)
                "1MISC\n"
               "9! ^]  Shell      ;K :K xK  Execute plugin K\n"
                  "cC  Execute entry  R ^V  Pick plugin\n"
-                 "cU  Manage session    =  Launch\n"
+                 "cU  Manage session    =  Launch app\n"
                  "cc  SSHFS mount       u  Unmount\n"
               "9] ^P  Prompt/run cmd    L  Lock\n"};
 
@@ -5247,10 +5254,22 @@ nochange:
                                setdirwatch();
                                goto begin;
                        case SEL_LAUNCH:
-                               if (getutil(utils[UTIL_NLAUNCH])) {
-                                       spawn(utils[UTIL_NLAUNCH], "0", NULL, path, F_NORMAL);
-                                       break;
-                               } // fallthrough
+                               mkpath(plugindir, utils[UTIL_LAUNCH], newpath);
+                               if ((getutil(utils[UTIL_FZF]) || getutil(utils[UTIL_FZY]))
+                                   && access(newpath, X_OK) == 0) {
+                                       tmp = newpath;
+                                       r = F_NORMAL;
+                               } else {
+                                       tmp = xreadline(NULL, messages[MSG_APP_NAME]);
+                                       r = F_NOWAIT | F_NOTRACE | F_MULTI;
+                               }
+
+                               if (tmp && *tmp) // NOLINT
+                                       spawn(tmp, "0", NULL, path, r);
+
+                               if (cfg.filtermode)
+                                       presel = FILTER;
+                               goto nochange;
                        default: /* SEL_RUNCMD */
 #ifndef NORL
                                if (cfg.picker) {
@@ -5264,7 +5283,7 @@ nochange:
                                                goto nochange;
                                }
 #endif
-                               if (tmp && tmp[0]) // NOLINT
+                               if (tmp && *tmp) // NOLINT
                                        prompt_run(tmp, (ndents ? dents[cur].name : ""), path);
                        }