mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Move nlaunch to plugins as launch
This commit is contained in:
parent
77ebfff98b
commit
d5512462af
|
@ -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.
|
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).
|
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`.
|
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:
|
Notes:
|
||||||
|
|
||||||
|
@ -232,7 +232,7 @@ The list below is from the **dev branch**. Press <kbd>?</kbd> in `nnn` to see th
|
||||||
MISC
|
MISC
|
||||||
! ^] Shell ;K :K xK Execute plugin K
|
! ^] Shell ;K :K xK Execute plugin K
|
||||||
C Execute entry R ^V Pick plugin
|
C Execute entry R ^V Pick plugin
|
||||||
U Manage session = Launch
|
U Manage session = Launch app
|
||||||
c Remote mount u Unmount
|
c Remote mount u Unmount
|
||||||
] ^P Prompt/run cmd L Lock
|
] ^P Prompt/run cmd L Lock
|
||||||
```
|
```
|
||||||
|
|
|
@ -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
|
|
|
@ -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
|
|
|
@ -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 |
|
| 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) |
|
| dragdrop | Drag/drop files from/into nnn | sh | [dragon](https://github.com/mwh/dragon) |
|
||||||
| exetoggle | Toggle executable status of hovered file | sh | chmod |
|
| 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 |
|
| 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 |
|
| fzopen | Fuzzy find a file in dir subtree and edit or open | sh | fzy, xdg-open |
|
||||||
| getplugs | Update plugins | sh | curl |
|
| 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 |
|
| 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 |
|
| ipinfo | Fetch external IP address and whois information | sh | curl, whois |
|
||||||
| kdeconnect | Send selected files to an Android device | sh | kdeconnect-cli |
|
| kdeconnect | Send selected files to an Android device | sh | kdeconnect-cli |
|
||||||
|
| launch | GUI application launcher | sh | fzf/fzy |
|
||||||
| mediainf | Show media information | sh | mediainfo |
|
| 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/) |
|
| 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/) |
|
| 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.
|
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
|
## Executing plugins
|
||||||
|
|
||||||
**Method 1:** Directly with <kbd>:key</kbd>:
|
**Method 1:** Directly with <kbd>:key</kbd>:
|
||||||
|
|
|
@ -31,13 +31,13 @@ prompt () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$(is_cmd_exists sudo)" -eq "0" ]; then
|
# if [ "$(is_cmd_exists sudo)" -eq "0" ]; then
|
||||||
sucmd=sudo
|
# sucmd=sudo
|
||||||
elif [ "$(is_cmd_exists doas)" -eq "0" ]; then
|
# elif [ "$(is_cmd_exists doas)" -eq "0" ]; then
|
||||||
sucmd=doas
|
# sucmd=doas
|
||||||
else
|
# else
|
||||||
sucmd=: # noop
|
# sucmd=: # noop
|
||||||
fi
|
# fi
|
||||||
|
|
||||||
# backup any earlier plugins
|
# backup any earlier plugins
|
||||||
if [ -d "$PLUGIN_DIR" ]; then
|
if [ -d "$PLUGIN_DIR" ]; then
|
||||||
|
@ -65,5 +65,4 @@ for f in $(find . -maxdepth 1 \( ! -iname "." ! -iname "*.md" \)); do
|
||||||
done
|
done
|
||||||
cd ../.. || exit 1
|
cd ../.. || exit 1
|
||||||
|
|
||||||
$sucmd mv -vf nnn-master/misc/nlaunch/nlaunch /usr/local/bin/
|
|
||||||
rm -rf nnn-master/ master.tar.gz
|
rm -rf nnn-master/ master.tar.gz
|
||||||
|
|
42
plugins/launch
Executable file
42
plugins/launch
Executable file
|
@ -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
|
15
plugins/nuke
15
plugins/nuke
|
@ -1,11 +1,12 @@
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# nuke: a sample script to play files in different apps by file type and mime
|
# Description: Sample script to play files in apps by file type or mime
|
||||||
# shell: POSIX compliant
|
|
||||||
# usage: nuke filepath
|
|
||||||
#
|
#
|
||||||
# nnn integration:
|
# Shell: POSIX compliant
|
||||||
|
# Usage: nuke filepath
|
||||||
|
#
|
||||||
|
# Integration with nnn:
|
||||||
# 1. Export the required config:
|
# 1. Export the required config:
|
||||||
# export NNN_OPENER=/absolute/path/to/nuke
|
# export NNN_OPENER=/absolute/path/to/nuke
|
||||||
# # Otherwise, if nuke is in $PATH
|
# # Otherwise, if nuke is in $PATH
|
||||||
|
@ -14,7 +15,7 @@
|
||||||
# nnn -c
|
# nnn -c
|
||||||
# 3. nuke can use nnn plugins (e.g. mocplay is used for audio), $PATH is updated.
|
# 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.
|
# Inspired by ranger's scope.sh, modified for usage with nnn.
|
||||||
#
|
#
|
||||||
# Tries to play 'file' (1st argument) in the following order:
|
# Tries to play 'file' (1st argument) in the following order:
|
||||||
|
@ -22,7 +23,7 @@
|
||||||
# ii. by mime (image, video, audio, pdf)
|
# ii. by mime (image, video, audio, pdf)
|
||||||
# iii. by mime (other file types)
|
# iii. by mime (other file types)
|
||||||
#
|
#
|
||||||
# modification tips:
|
# Modification tips:
|
||||||
# 1. Invokes CLI utilities by default. Set GUI to 1 to enable GUI apps.
|
# 1. Invokes CLI utilities by default. Set GUI to 1 to enable GUI apps.
|
||||||
# 2. PAGER is "less -R".
|
# 2. PAGER is "less -R".
|
||||||
# 3. Start GUI apps in bg to unblock. Redirect stdout and strerr if required.
|
# 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.
|
# Feel free to change the utilities to your favourites and add more mimes.
|
||||||
#
|
#
|
||||||
# defaults:
|
# Defaults:
|
||||||
# By extension (only the enbaled ones):
|
# By extension (only the enbaled ones):
|
||||||
# most archives: list with atool, bsdtar
|
# most archives: list with atool, bsdtar
|
||||||
# rar: list with unrar
|
# rar: list with unrar
|
||||||
|
|
37
src/nnn.c
37
src/nnn.c
|
@ -369,7 +369,7 @@ static bool g_plinit = FALSE;
|
||||||
#define UTIL_TAR 4
|
#define UTIL_TAR 4
|
||||||
#define UTIL_LOCKER 5
|
#define UTIL_LOCKER 5
|
||||||
#define UTIL_CMATRIX 6
|
#define UTIL_CMATRIX 6
|
||||||
#define UTIL_NLAUNCH 7
|
#define UTIL_LAUNCH 7
|
||||||
#define UTIL_SH_EXEC 8
|
#define UTIL_SH_EXEC 8
|
||||||
#define UTIL_ARCHIVEMOUNT 9
|
#define UTIL_ARCHIVEMOUNT 9
|
||||||
#define UTIL_SSHFS 10
|
#define UTIL_SSHFS 10
|
||||||
|
@ -377,6 +377,8 @@ static bool g_plinit = FALSE;
|
||||||
#define UTIL_VI 12
|
#define UTIL_VI 12
|
||||||
#define UTIL_LESS 13
|
#define UTIL_LESS 13
|
||||||
#define UTIL_SH 14
|
#define UTIL_SH 14
|
||||||
|
#define UTIL_FZF 15
|
||||||
|
#define UTIL_FZY 16
|
||||||
|
|
||||||
/* Utilities to open files, run actions */
|
/* Utilities to open files, run actions */
|
||||||
static char * const utils[] = {
|
static char * const utils[] = {
|
||||||
|
@ -399,7 +401,7 @@ static char * const utils[] = {
|
||||||
"vlock",
|
"vlock",
|
||||||
#endif
|
#endif
|
||||||
"cmatrix",
|
"cmatrix",
|
||||||
"nlaunch",
|
"launch",
|
||||||
"sh -c",
|
"sh -c",
|
||||||
"archivemount",
|
"archivemount",
|
||||||
"sshfs",
|
"sshfs",
|
||||||
|
@ -407,6 +409,8 @@ static char * const utils[] = {
|
||||||
"vi",
|
"vi",
|
||||||
"less",
|
"less",
|
||||||
"sh",
|
"sh",
|
||||||
|
"fzf",
|
||||||
|
"fzy",
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Common strings */
|
/* Common strings */
|
||||||
|
@ -451,6 +455,7 @@ static char * const utils[] = {
|
||||||
#define MSG_FEW_COLOUMNS 38
|
#define MSG_FEW_COLOUMNS 38
|
||||||
#define MSG_REMOTE_OPTS 39
|
#define MSG_REMOTE_OPTS 39
|
||||||
#define MSG_RCLONE_DELAY 40
|
#define MSG_RCLONE_DELAY 40
|
||||||
|
#define MSG_APP_NAME 41
|
||||||
|
|
||||||
static const char * const messages[] = {
|
static const char * const messages[] = {
|
||||||
"no traversal",
|
"no traversal",
|
||||||
|
@ -493,7 +498,8 @@ static const char * const messages[] = {
|
||||||
"entry exists",
|
"entry exists",
|
||||||
"too few columns!",
|
"too few columns!",
|
||||||
"'s'shfs / 'r'clone?",
|
"'s'shfs / 'r'clone?",
|
||||||
"may take a while, try refresh"
|
"may take a while, try refresh",
|
||||||
|
"app name: ",
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Supported configuration environment variables */
|
/* Supported configuration environment variables */
|
||||||
|
@ -2098,6 +2104,7 @@ static int filterentries(char *path)
|
||||||
if (len == 1)
|
if (len == 1)
|
||||||
cur = oldcur;
|
cur = oldcur;
|
||||||
goto end;
|
goto end;
|
||||||
|
case '=': // fallthrough /* Launch app */
|
||||||
case ':': // fallthrough /* Run plugin keys */
|
case ':': // fallthrough /* Run plugin keys */
|
||||||
case ';': // fallthrough
|
case ';': // fallthrough
|
||||||
case '?': /* Help and config key, '?' is an invalid regex */
|
case '?': /* Help and config key, '?' is an invalid regex */
|
||||||
|
@ -3497,7 +3504,7 @@ static void show_help(const char *path)
|
||||||
"1MISC\n"
|
"1MISC\n"
|
||||||
"9! ^] Shell ;K :K xK Execute plugin K\n"
|
"9! ^] Shell ;K :K xK Execute plugin K\n"
|
||||||
"cC Execute entry R ^V Pick plugin\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"
|
"cc SSHFS mount u Unmount\n"
|
||||||
"9] ^P Prompt/run cmd L Lock\n"};
|
"9] ^P Prompt/run cmd L Lock\n"};
|
||||||
|
|
||||||
|
@ -5247,10 +5254,22 @@ nochange:
|
||||||
setdirwatch();
|
setdirwatch();
|
||||||
goto begin;
|
goto begin;
|
||||||
case SEL_LAUNCH:
|
case SEL_LAUNCH:
|
||||||
if (getutil(utils[UTIL_NLAUNCH])) {
|
mkpath(plugindir, utils[UTIL_LAUNCH], newpath);
|
||||||
spawn(utils[UTIL_NLAUNCH], "0", NULL, path, F_NORMAL);
|
if ((getutil(utils[UTIL_FZF]) || getutil(utils[UTIL_FZY]))
|
||||||
break;
|
&& access(newpath, X_OK) == 0) {
|
||||||
} // fallthrough
|
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 */
|
default: /* SEL_RUNCMD */
|
||||||
#ifndef NORL
|
#ifndef NORL
|
||||||
if (cfg.picker) {
|
if (cfg.picker) {
|
||||||
|
@ -5264,7 +5283,7 @@ nochange:
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (tmp && tmp[0]) // NOLINT
|
if (tmp && *tmp) // NOLINT
|
||||||
prompt_run(tmp, (ndents ? dents[cur].name : ""), path);
|
prompt_run(tmp, (ndents ? dents[cur].name : ""), path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue