mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
Option -P: specify plugin key to run on start
This commit is contained in:
parent
cafcf1c485
commit
1b5c3096ca
|
@ -27,6 +27,7 @@ _nnn ()
|
||||||
-n
|
-n
|
||||||
-o
|
-o
|
||||||
-p
|
-p
|
||||||
|
-P
|
||||||
-Q
|
-Q
|
||||||
-r
|
-r
|
||||||
-R
|
-R
|
||||||
|
@ -45,6 +46,9 @@ _nnn ()
|
||||||
return 1
|
return 1
|
||||||
elif [[ $prev == -p ]]; then
|
elif [[ $prev == -p ]]; then
|
||||||
COMPREPLY=( $(compgen -f -d -- "$cur") )
|
COMPREPLY=( $(compgen -f -d -- "$cur") )
|
||||||
|
elif [[ $prev == -P ]]; then
|
||||||
|
local plugins=$(echo $NNN_PLUG | awk -F: -v RS=\; '{print $1}')
|
||||||
|
COMPREPLY=( $(compgen -W "$plugins" -- "$cur") )
|
||||||
elif [[ $prev == -s ]]; then
|
elif [[ $prev == -s ]]; then
|
||||||
local sessions_dir=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/sessions
|
local sessions_dir=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/sessions
|
||||||
COMPREPLY=( $(cd "$sessions_dir" && compgen -f -d -- "$cur") )
|
COMPREPLY=( $(cd "$sessions_dir" && compgen -f -d -- "$cur") )
|
||||||
|
|
|
@ -26,6 +26,7 @@ complete -c nnn -s l -r -d 'lines to move per scroll'
|
||||||
complete -c nnn -s n -d 'start in type-to-nav mode'
|
complete -c nnn -s n -d 'start in type-to-nav mode'
|
||||||
complete -c nnn -s o -d 'open files only on Enter'
|
complete -c nnn -s o -d 'open files only on Enter'
|
||||||
complete -c nnn -s p -r -d 'copy selection to file' -a '-\tstdout'
|
complete -c nnn -s p -r -d 'copy selection to file' -a '-\tstdout'
|
||||||
|
complete -c nnn -s P -r -d 'plugin key to run' -x -a '(echo $NNN_PLUG | awk -F: -v RS=\; \'{print $1"\t"$2}\')'
|
||||||
complete -c nnn -s Q -d 'disable quit confirmation'
|
complete -c nnn -s Q -d 'disable quit confirmation'
|
||||||
complete -c nnn -s r -d 'show cp, mv progress (Linux-only)'
|
complete -c nnn -s r -d 'show cp, mv progress (Linux-only)'
|
||||||
complete -c nnn -s R -d 'disable rollover at edges'
|
complete -c nnn -s R -d 'disable rollover at edges'
|
||||||
|
|
|
@ -24,6 +24,7 @@ args=(
|
||||||
'(-n)-n[start in type-to-nav mode]'
|
'(-n)-n[start in type-to-nav mode]'
|
||||||
'(-o)-o[open files only on Enter]'
|
'(-o)-o[open files only on Enter]'
|
||||||
'(-p)-p[copy selection to file]:file name'
|
'(-p)-p[copy selection to file]:file name'
|
||||||
|
'(-P)-P[plugin key to runn]:key char'
|
||||||
'(-Q)-Q[disable quit confirmation]'
|
'(-Q)-Q[disable quit confirmation]'
|
||||||
'(-r)-r[show cp, mv progress (Linux-only)]'
|
'(-r)-r[show cp, mv progress (Linux-only)]'
|
||||||
'(-R)-R[disable rollover at edges]'
|
'(-R)-R[disable rollover at edges]'
|
||||||
|
|
32
src/nnn.c
32
src/nnn.c
|
@ -5227,7 +5227,7 @@ static bool cdprep(char *lastdir, char *lastname, char *path, char *newpath)
|
||||||
return cfg.filtermode;
|
return cfg.filtermode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool browse(char *ipath, const char *session)
|
static bool browse(char *ipath, const char *session, int pkey)
|
||||||
{
|
{
|
||||||
char newpath[PATH_MAX] __attribute__ ((aligned));
|
char newpath[PATH_MAX] __attribute__ ((aligned));
|
||||||
char rundir[PATH_MAX] __attribute__ ((aligned));
|
char rundir[PATH_MAX] __attribute__ ((aligned));
|
||||||
|
@ -5269,7 +5269,7 @@ static bool browse(char *ipath, const char *session)
|
||||||
|
|
||||||
newpath[0] = rundir[0] = runfile[0] = '\0';
|
newpath[0] = rundir[0] = runfile[0] = '\0';
|
||||||
|
|
||||||
presel = cfg.filtermode ? FILTER : 0;
|
presel = pkey ? ';' : (cfg.filtermode ? FILTER : 0);
|
||||||
|
|
||||||
dents = xrealloc(dents, total_dents * sizeof(struct entry));
|
dents = xrealloc(dents, total_dents * sizeof(struct entry));
|
||||||
if (!dents)
|
if (!dents)
|
||||||
|
@ -6273,10 +6273,16 @@ nochange:
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = xstrsncpy(g_buf, messages[MSG_PLUGIN_KEYS], CMD_LEN_MAX);
|
if (!pkey) {
|
||||||
printkeys(plug, g_buf + r - 1, maxplug);
|
r = xstrsncpy(g_buf, messages[MSG_PLUGIN_KEYS], CMD_LEN_MAX);
|
||||||
printmsg(g_buf);
|
printkeys(plug, g_buf + r - 1, maxplug);
|
||||||
r = get_input(NULL);
|
printmsg(g_buf);
|
||||||
|
r = get_input(NULL);
|
||||||
|
} else {
|
||||||
|
r = pkey;
|
||||||
|
pkey = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
if (r != '\r') {
|
if (r != '\r') {
|
||||||
endselection();
|
endselection();
|
||||||
tmp = get_kv_val(plug, NULL, r, maxplug, NNN_PLUG);
|
tmp = get_kv_val(plug, NULL, r, maxplug, NNN_PLUG);
|
||||||
|
@ -6743,6 +6749,7 @@ static void usage(void)
|
||||||
" -n type-to-nav mode\n"
|
" -n type-to-nav mode\n"
|
||||||
" -o open files only on Enter\n"
|
" -o open files only on Enter\n"
|
||||||
" -p file selection file [stdout if '-']\n"
|
" -p file selection file [stdout if '-']\n"
|
||||||
|
" -P key run plugin key\n"
|
||||||
" -Q no quit confirmation\n"
|
" -Q no quit confirmation\n"
|
||||||
" -r use advcpmv patched cp, mv\n"
|
" -r use advcpmv patched cp, mv\n"
|
||||||
" -R no rollover at edges\n"
|
" -R no rollover at edges\n"
|
||||||
|
@ -6888,7 +6895,7 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *arg = NULL;
|
char *arg = NULL;
|
||||||
char *session = NULL;
|
char *session = NULL;
|
||||||
int fd, opt, sort = 0;
|
int fd, opt, sort = 0, pkey = '\0'; /* Plugin key */
|
||||||
#ifndef NOMOUSE
|
#ifndef NOMOUSE
|
||||||
mmask_t mask;
|
mmask_t mask;
|
||||||
char *middle_click_env = xgetenv(env_cfg[NNN_MCLICK], "\0");
|
char *middle_click_env = xgetenv(env_cfg[NNN_MCLICK], "\0");
|
||||||
|
@ -6905,13 +6912,14 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
while ((opt = (env_opts_id > 0
|
while ((opt = (env_opts_id > 0
|
||||||
? env_opts[--env_opts_id]
|
? env_opts[--env_opts_id]
|
||||||
: getopt(argc, argv, "Ab:cdeEfFgHKl:nop:QrRs:St:T:Vxh"))) != -1) {
|
: getopt(argc, argv, "Ab:cdeEfFgHKl:nop:P:QrRs:St:T:Vxh"))) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'A':
|
case 'A':
|
||||||
cfg.autoselect = 0;
|
cfg.autoselect = 0;
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
arg = optarg;
|
if (env_opts_id < 0)
|
||||||
|
arg = optarg;
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
cfg.cliopener = 1;
|
cfg.cliopener = 1;
|
||||||
|
@ -6973,6 +6981,10 @@ int main(int argc, char *argv[])
|
||||||
unlink(selpath);
|
unlink(selpath);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'P':
|
||||||
|
if (env_opts_id < 0 && !optarg[1])
|
||||||
|
pkey = optarg[0];
|
||||||
|
break;
|
||||||
case 'Q':
|
case 'Q':
|
||||||
g_states |= STATE_FORCEQUIT;
|
g_states |= STATE_FORCEQUIT;
|
||||||
break;
|
break;
|
||||||
|
@ -7229,7 +7241,7 @@ int main(int argc, char *argv[])
|
||||||
if (sort)
|
if (sort)
|
||||||
set_sort_flags(sort);
|
set_sort_flags(sort);
|
||||||
|
|
||||||
opt = browse(initpath, session);
|
opt = browse(initpath, session, pkey);
|
||||||
|
|
||||||
#ifndef NOMOUSE
|
#ifndef NOMOUSE
|
||||||
mousemask(mask, NULL);
|
mousemask(mask, NULL);
|
||||||
|
|
Loading…
Reference in a new issue