README.md | 4 ++-- misc/nlaunch/README.md | 7 ------- misc/nlaunch/nlaunch | 29 ----------------------------- plugins/README.md | 5 ++--- plugins/getplugs | 15 +++++++-------- plugins/launch | 42 ++++++++++++++++++++++++++++++++++++++++++ plugins/nuke | 15 ++++++++------- src/nnn.c | 37 ++++++++++++++++++++++++++++--------- diff --git a/README.md b/README.md index d6a5b470bcdfa921744ea34ebf7f623a41b31237..05e226e242531b49f1ea3ed3cf39827ae4bb3ebf 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ 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 @@ z Size E Extn t Time 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 index 2b267eea10d9265e74ce68df7234fe6d717673c1..0000000000000000000000000000000000000000 --- a/misc/nlaunch/README.md +++ /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 index 123e62dad24ebbc46298e9ad5f7dd9eb09a59d09..0000000000000000000000000000000000000000 --- a/misc/nlaunch/nlaunch +++ /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 diff --git a/plugins/README.md b/plugins/README.md index 094238b7131aa6739d0cc8ad7216fa8420cc5df1..1906df7ead67db88f4c79b11c6e83055e5da0339 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -20,7 +20,7 @@ | chksum | Create and verify checksums | sh | md5sum,
sha256sum | | 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
(optional fd) | +| fzcd | Change to the directory of a fuzzy-selected file/dir | sh | fzf/fzy
(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 @@ | imgur | Upload an image to imgur (from [imgur-screenshot](https://github.com/jomo/imgur-screenshot)) | bash | - | | 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/) | @@ -64,8 +65,6 @@ curl -Ls https://raw.githubusercontent.com/jarun/nnn/master/plugins/getplugs | sh 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 diff --git a/plugins/getplugs b/plugins/getplugs index ff40360df0302efbda5d533410735ff95e452fb2..169c4aa40ffe0f0e124ccde43fa7faae203a988a 100755 --- a/plugins/getplugs +++ b/plugins/getplugs @@ -31,13 +31,13 @@ op="true" 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 @@ fi 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 index 0000000000000000000000000000000000000000..f1b8a73b555558913ca9080148d94208e0b2782f --- /dev/null +++ b/plugins/launch @@ -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 diff --git a/plugins/nuke b/plugins/nuke index 1109894380f6aec07f1462762bd398178a191b3e..2bab939ab8fc42cca6a29a988e02b664c8768b60 100755 --- a/plugins/nuke +++ b/plugins/nuke @@ -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 @@ # 2. Run nnn with the program option to indicate a CLI opener # 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 @@ # i. by extension # 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 @@ # 6. On a DE, try 'xdg-open' in handle_fallback() as last resort. # # 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 diff --git a/src/nnn.c b/src/nnn.c index 4eb4112a72a5886a357e1e7d04a4db9a4257de66..c406d6e713335292b8d71d1c89806d39f25f1007 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -369,7 +369,7 @@ #define UTIL_UNZIP 3 #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 @@ #define UTIL_RCLONE 11 #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 @@ #else "vlock", #endif "cmatrix", - "nlaunch", + "launch", "sh -c", "archivemount", "sshfs", @@ -407,6 +409,8 @@ "rclone", "vi", "less", "sh", + "fzf", + "fzy", }; /* Common strings */ @@ -451,6 +455,7 @@ #define MSG_EXISTS 37 #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 @@ "0 files", "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 @@ *ch = CONTROL('_'); // fallthrough 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 @@ "cz Size E Extn t Time\n" "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 @@ } 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 @@ if (presel == MSGWAIT) goto nochange; } #endif - if (tmp && tmp[0]) // NOLINT + if (tmp && *tmp) // NOLINT prompt_run(tmp, (ndents ? dents[cur].name : ""), path); }