mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
Extend plugin mechanism to arbitrary commands
This commit is contained in:
parent
cb916661c8
commit
5bebd4ac67
|
@ -50,7 +50,7 @@ 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
|
||||||
- Plugins with configurable keybinds
|
- Run plugins (or commands) with configurable keybinds
|
||||||
- FreeDesktop compliant trash (needs trash-cli)
|
- FreeDesktop compliant trash (needs trash-cli)
|
||||||
- SSHFS mounts (needs sshfs)
|
- SSHFS mounts (needs sshfs)
|
||||||
- Cross-dir file/all/range selection
|
- Cross-dir file/all/range selection
|
||||||
|
@ -147,7 +147,7 @@ There is no config file. Associated files are stored under `${XDG_CONFIG_HOME:-$
|
||||||
| Example `export` | Description |
|
| Example `export` | Description |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `NNN_BMS='d:~/Documents;D:~/Docs archive/'` | key-bookmark pairs [max 10] |
|
| `NNN_BMS='d:~/Documents;D:~/Docs archive/'` | key-bookmark pairs [max 10] |
|
||||||
| `NNN_PLUG='o:fzy-open;p:mocplay;m:nmount;t:thumb'` | key-plugin pairs (<kbd>:key</kbd> to run) [max 10] |
|
| `NNN_PLUG='o:fzy-open;p:mocplay;m:nmount;t:thumb'` | key-plugin pairs (<kbd>:key</kbd> to run) [max 15] |
|
||||||
| `NNN_USE_EDITOR=1` | open text files in `$VISUAL` (else `$EDITOR`, fallback vi) |
|
| `NNN_USE_EDITOR=1` | open text files in `$VISUAL` (else `$EDITOR`, fallback vi) |
|
||||||
| `NNN_CONTEXT_COLORS='1234'` | specify per context color [default: '4444' (all blue)] |
|
| `NNN_CONTEXT_COLORS='1234'` | specify per context color [default: '4444' (all blue)] |
|
||||||
| `NNN_SSHFS_OPTS='sshfs -o reconnect,idmap=user'` | specify SSHFS options |
|
| `NNN_SSHFS_OPTS='sshfs -o reconnect,idmap=user'` | specify SSHFS options |
|
||||||
|
|
|
@ -66,6 +66,10 @@ Plugins are installed to `${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins`. You ca
|
||||||
|
|
||||||
With this, plugin `fzy-open` can be run with the keybind <kbd>:o</kbd>, `mocplay` can be run with <kbd>:p</kbd> and so on... The key vs. plugin pairs are shown in the help and config screen. Up to 10 plugins can have such keybinds.
|
With this, plugin `fzy-open` can be run with the keybind <kbd>:o</kbd>, `mocplay` can be run with <kbd>:p</kbd> and so on... The key vs. plugin pairs are shown in the help and config screen. Up to 10 plugins can have such keybinds.
|
||||||
|
|
||||||
|
To assign keys to arbitrary commands (non-shell interpreted) and invoke like plugins, add `_` (underscore) before the command. For example:
|
||||||
|
|
||||||
|
export NNN_PLUG='x:_chmod +x;o:fzy-open'
|
||||||
|
|
||||||
**Method 2:** Use the _pick plugin_ shortcut to visit the plugin directory and execute a plugin. Repeating the same shortcut cancels the operation and puts you back in the original directory.
|
**Method 2:** Use the _pick plugin_ shortcut to visit the plugin directory and execute a plugin. Repeating the same shortcut cancels the operation and puts you back in the original directory.
|
||||||
|
|
||||||
## Create your own plugins
|
## Create your own plugins
|
||||||
|
|
14
src/nnn.c
14
src/nnn.c
|
@ -128,7 +128,7 @@
|
||||||
#define MSGWAIT '$'
|
#define MSGWAIT '$'
|
||||||
#define REGEX_MAX 48
|
#define REGEX_MAX 48
|
||||||
#define BM_MAX 10
|
#define BM_MAX 10
|
||||||
#define PLUGIN_MAX 10
|
#define PLUGIN_MAX 15
|
||||||
#define ENTRY_INCR 64 /* Number of dir 'entry' structures to allocate per shot */
|
#define ENTRY_INCR 64 /* Number of dir 'entry' structures to allocate per shot */
|
||||||
#define NAMEBUF_INCR 0x800 /* 64 dir entries at once, avg. 32 chars per filename = 64*32B = 2KB */
|
#define NAMEBUF_INCR 0x800 /* 64 dir entries at once, avg. 32 chars per filename = 64*32B = 2KB */
|
||||||
#define DESCRIPTOR_LEN 32
|
#define DESCRIPTOR_LEN 32
|
||||||
|
@ -4941,13 +4941,21 @@ nochange:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sel == SEL_PLUGKEY) {
|
if (sel == SEL_PLUGKEY) {
|
||||||
|
uchar flag = F_NORMAL;
|
||||||
|
|
||||||
r = get_input("");
|
r = get_input("");
|
||||||
tmp = get_kv_val(plug, NULL, r, PLUGIN_MAX, FALSE);
|
tmp = get_kv_val(plug, NULL, r, PLUGIN_MAX, FALSE);
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
goto nochange;
|
goto nochange;
|
||||||
|
|
||||||
mkpath(plugindir, tmp, newpath);
|
if (tmp[0] == '_' && tmp[1]) {
|
||||||
spawn(newpath, (ndents ? dents[cur].name : NULL), path, path, F_NORMAL);
|
xstrlcpy(newpath, ++tmp, PATH_MAX);
|
||||||
|
flag = F_CLI | F_CONFIRM;
|
||||||
|
} else
|
||||||
|
mkpath(plugindir, tmp, newpath);
|
||||||
|
|
||||||
|
spawn(newpath, (ndents ? dents[cur].name : NULL),
|
||||||
|
path, path, flag);
|
||||||
|
|
||||||
if (cfg.filtermode)
|
if (cfg.filtermode)
|
||||||
presel = FILTER;
|
presel = FILTER;
|
||||||
|
|
Loading…
Reference in a new issue