mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Allow launching plugins with Alt + plugin's key (#569)
* Allow launching plugins with Alt + plugin's key * Fix Alt key in filter/prompts modes * Fix handling Alt key in nextsel() In filter mode: run the associated plugin. In prompt mode: just throw out the Alt+key input. In nextsel(): differentiate Alt+key and Esc
This commit is contained in:
parent
770bb47daf
commit
2200a1c9be
6
nnn.1
6
nnn.1
|
@ -338,8 +338,10 @@ separated by \fI;\fR:
|
||||||
export NNN_PLUG='f:finder;o:fzopen;p:mocplay;d:diffs;t:nmount;v:imgview'
|
export NNN_PLUG='f:finder;o:fzopen;p:mocplay;d:diffs;t:nmount;v:imgview'
|
||||||
|
|
||||||
NOTES:
|
NOTES:
|
||||||
1. To run a plugin directly, press \fI;\fR followed by the plugin key.
|
1. To run a plugin directly, press \fI;\fR followed by the key_char.
|
||||||
2. To skip directory refresh after running a plugin, prefix with \fB-\fR.
|
2. Alternative way to run a plugin directly -
|
||||||
|
prefix with \fIAlt\fR (i.e. \fIAlt+key_char\fR).
|
||||||
|
3. To skip directory refresh after running a plugin, prefix with \fB-\fR.
|
||||||
|
|
||||||
export NNN_PLUG='m:-mediainf'
|
export NNN_PLUG='m:-mediainf'
|
||||||
.Ed
|
.Ed
|
||||||
|
|
|
@ -78,7 +78,7 @@ Plugins are installed to `${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins`.
|
||||||
|
|
||||||
## Invoking a plugin
|
## Invoking a plugin
|
||||||
|
|
||||||
Press the plugin shortcut (<kbd>;</kbd> or <kbd>^S</kbd>) followed by the assigned key. E.g., with the below config:
|
Press the plugin shortcut (<kbd>;</kbd> or <kbd>^S</kbd>) followed by the assigned key character. E.g., with the below config:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
export NNN_PLUG='f:finder;o:fzopen;p:mocplay;d:diffs;t:nmount;v:imgview'
|
export NNN_PLUG='f:finder;o:fzopen;p:mocplay;d:diffs;t:nmount;v:imgview'
|
||||||
|
@ -86,6 +86,8 @@ export NNN_PLUG='f:finder;o:fzopen;p:mocplay;d:diffs;t:nmount;v:imgview'
|
||||||
|
|
||||||
Plugin `finder` can be run with the keybind <kbd>;f</kbd>, `fzopen` can be run with <kbd>;o</kbd> and so on... The key vs. plugin pairs are shown in the help and config screen.
|
Plugin `finder` can be run with the keybind <kbd>;f</kbd>, `fzopen` can be run with <kbd>;o</kbd> and so on... The key vs. plugin pairs are shown in the help and config screen.
|
||||||
|
|
||||||
|
Alternative way to run a plugin directly - prefix with <kbd>Alt</kbd> (i.e. <kbd>Alt+key_char</kbd>).
|
||||||
|
|
||||||
To select and invoke a plugin from the plugin directory, press <kbd>Enter</kbd> (to _enter_ the plugin dir) after the plugin shortcut.
|
To select and invoke a plugin from the plugin directory, press <kbd>Enter</kbd> (to _enter_ the plugin dir) after the plugin shortcut.
|
||||||
|
|
||||||
#### Skip directory refresh after running a plugin
|
#### Skip directory refresh after running a plugin
|
||||||
|
|
37
src/nnn.c
37
src/nnn.c
|
@ -2284,6 +2284,18 @@ static int reventrycmp(const void *va, const void *vb)
|
||||||
|
|
||||||
static int (*entrycmpfn)(const void *va, const void *vb) = &entrycmp;
|
static int (*entrycmpfn)(const void *va, const void *vb) = &entrycmp;
|
||||||
|
|
||||||
|
/* In case of an error, resets *wch to Esc */
|
||||||
|
static int handle_alt_key(wint_t *wch)
|
||||||
|
{
|
||||||
|
timeout(0);
|
||||||
|
int r = get_wch(wch);
|
||||||
|
if (r == ERR)
|
||||||
|
*wch = 27;
|
||||||
|
cleartimeout();
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns SEL_* if key is bound and 0 otherwise.
|
* Returns SEL_* if key is bound and 0 otherwise.
|
||||||
* Also modifies the run and env pointers (used on SEL_{RUN,RUNARG}).
|
* Also modifies the run and env pointers (used on SEL_{RUN,RUNARG}).
|
||||||
|
@ -2311,6 +2323,18 @@ static int nextsel(int presel)
|
||||||
//DPRINTF_D(c);
|
//DPRINTF_D(c);
|
||||||
//DPRINTF_S(keyname(c));
|
//DPRINTF_S(keyname(c));
|
||||||
|
|
||||||
|
/* Handle Alt+key */
|
||||||
|
if (c == 27) {
|
||||||
|
timeout(0);
|
||||||
|
c = getch();
|
||||||
|
if (c != ERR) {
|
||||||
|
ungetch(c);
|
||||||
|
c = CONTROL('S');
|
||||||
|
} else
|
||||||
|
c = 27;
|
||||||
|
settimeout();
|
||||||
|
}
|
||||||
|
|
||||||
if (c == ERR && presel == MSGWAIT)
|
if (c == ERR && presel == MSGWAIT)
|
||||||
c = (cfg.filtermode || filterset()) ? FILTER : CONTROL('L');
|
c = (cfg.filtermode || filterset()) ? FILTER : CONTROL('L');
|
||||||
else if (c == FILTER || c == CONTROL('L'))
|
else if (c == FILTER || c == CONTROL('L'))
|
||||||
|
@ -2564,7 +2588,11 @@ static int filterentries(char *path, char *lastname)
|
||||||
#ifndef NOMOUSE
|
#ifndef NOMOUSE
|
||||||
case KEY_MOUSE: // fallthrough
|
case KEY_MOUSE: // fallthrough
|
||||||
#endif
|
#endif
|
||||||
case 27: /* Exit filter mode on Escape */
|
case 27: /* Exit filter mode on Escape and Alt+key */
|
||||||
|
if (handle_alt_key(ch) != ERR) {
|
||||||
|
unget_wch(*ch);
|
||||||
|
*ch = CONTROL('S');
|
||||||
|
}
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2776,7 +2804,10 @@ static char *xreadline(const char *prefill, const char *prompt)
|
||||||
len -= pos;
|
len -= pos;
|
||||||
pos = 0;
|
pos = 0;
|
||||||
continue;
|
continue;
|
||||||
case 27: /* Exit prompt on Escape */
|
case 27: /* Exit prompt on Escape, but just filter out Alt+key */
|
||||||
|
if (handle_alt_key(ch) != ERR)
|
||||||
|
continue;
|
||||||
|
|
||||||
len = 0;
|
len = 0;
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
@ -4097,7 +4128,7 @@ static void show_help(const char *path)
|
||||||
"9x ^X Delete%-18cE Edit sel\n"
|
"9x ^X Delete%-18cE Edit sel\n"
|
||||||
"c* Toggle exe%-14c> Export list\n"
|
"c* Toggle exe%-14c> Export list\n"
|
||||||
"1MISC\n"
|
"1MISC\n"
|
||||||
"9; ^S Select plugin%-11c= Launch app\n"
|
"5Alt ; ^S Select plugin%-11c= Launch app\n"
|
||||||
"9! ^] Shell%-19c] Cmd prompt\n"
|
"9! ^] Shell%-19c] Cmd prompt\n"
|
||||||
"cc Connect remote%-10cu Unmount\n"
|
"cc Connect remote%-10cu Unmount\n"
|
||||||
"9t ^T Sort toggles%-12cs Manage session\n"
|
"9t ^T Sort toggles%-12cs Manage session\n"
|
||||||
|
|
Loading…
Reference in a new issue