mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Refactor plugin handling
This commit is contained in:
parent
5676dfe682
commit
bffadf09c5
136
src/nnn.c
136
src/nnn.c
|
@ -5245,10 +5245,76 @@ nochange:
|
|||
xstrlcpy(lastname, tmp, NAME_MAX + 1);
|
||||
goto begin;
|
||||
}
|
||||
case SEL_PLUGKEY: // fallthrough
|
||||
case SEL_PLUGIN:
|
||||
/* Check if directory is accessible */
|
||||
if (!xdiraccess(plugindir)) {
|
||||
printwarn(&presel);
|
||||
goto nochange;
|
||||
}
|
||||
|
||||
if (sel == SEL_PLUGKEY) {
|
||||
xstrlcpy(g_buf, messages[MSG_PLUGIN_KEYS], CMD_LEN_MAX);
|
||||
printkeys(plug, g_buf + strlen(g_buf), PLUGIN_MAX);
|
||||
printprompt(g_buf);
|
||||
r = get_input(NULL);
|
||||
tmp = get_kv_val(plug, NULL, r, PLUGIN_MAX, FALSE);
|
||||
if (!tmp) {
|
||||
printwait(messages[MSG_INVALID_KEY], &presel);
|
||||
goto nochange;
|
||||
}
|
||||
|
||||
if (tmp[0] == '-' && tmp[1]) {
|
||||
++tmp;
|
||||
r = FALSE; /* Do not refresh dir after completion */
|
||||
} else
|
||||
r = TRUE;
|
||||
|
||||
if (!run_selected_plugin(&path, tmp, newpath,
|
||||
(ndents ? dents[cur].name : NULL),
|
||||
&lastname, &lastdir)) {
|
||||
printwait(messages[MSG_FAILED], &presel);
|
||||
goto nochange;
|
||||
}
|
||||
|
||||
if (!r) {
|
||||
clearprompt();
|
||||
goto nochange;
|
||||
}
|
||||
|
||||
if (ndents)
|
||||
copycurname();
|
||||
} else {
|
||||
cfg.runplugin ^= 1;
|
||||
if (!cfg.runplugin && rundir[0]) {
|
||||
/*
|
||||
* If toggled, and still in the plugin dir,
|
||||
* switch to original directory
|
||||
*/
|
||||
if (strcmp(path, plugindir) == 0) {
|
||||
xstrlcpy(path, rundir, PATH_MAX);
|
||||
xstrlcpy(lastname, runfile, NAME_MAX);
|
||||
rundir[0] = runfile[0] = '\0';
|
||||
setdirwatch();
|
||||
goto begin;
|
||||
}
|
||||
|
||||
/* Otherwise, initiate choosing plugin again */
|
||||
cfg.runplugin = 1;
|
||||
}
|
||||
|
||||
xstrlcpy(rundir, path, PATH_MAX);
|
||||
xstrlcpy(path, plugindir, PATH_MAX);
|
||||
if (ndents)
|
||||
xstrlcpy(runfile, dents[cur].name, NAME_MAX);
|
||||
cfg.runctx = cfg.curctx;
|
||||
lastname[0] = '\0';
|
||||
}
|
||||
setdirwatch();
|
||||
clearfilter();
|
||||
goto begin;
|
||||
case SEL_EXEC: // fallthrough
|
||||
case SEL_SHELL: // fallthrough
|
||||
case SEL_PLUGKEY: // fallthrough
|
||||
case SEL_PLUGIN: // fallthrough
|
||||
case SEL_LAUNCH: // fallthrough
|
||||
case SEL_RUNCMD:
|
||||
endselection();
|
||||
|
@ -5262,72 +5328,6 @@ nochange:
|
|||
setenv(envs[ENV_NCUR], (ndents ? dents[cur].name : ""), 1);
|
||||
spawn(shell, NULL, NULL, path, F_CLI);
|
||||
break;
|
||||
case SEL_PLUGKEY: // fallthrough
|
||||
case SEL_PLUGIN:
|
||||
/* Check if directory is accessible */
|
||||
if (!xdiraccess(plugindir)) {
|
||||
printwarn(&presel);
|
||||
goto nochange;
|
||||
}
|
||||
|
||||
if (sel == SEL_PLUGKEY) {
|
||||
xstrlcpy(g_buf, messages[MSG_PLUGIN_KEYS], CMD_LEN_MAX);
|
||||
printkeys(plug, g_buf + strlen(g_buf), PLUGIN_MAX);
|
||||
printprompt(g_buf);
|
||||
r = get_input(NULL);
|
||||
tmp = get_kv_val(plug, NULL, r, PLUGIN_MAX, FALSE);
|
||||
if (!tmp) {
|
||||
printwait(messages[MSG_INVALID_KEY], &presel);
|
||||
goto nochange;
|
||||
}
|
||||
|
||||
if (tmp[0] == '-' && tmp[1]) {
|
||||
++tmp;
|
||||
r = FALSE; /* Do not refresh dir after completion */
|
||||
} else
|
||||
r = TRUE;
|
||||
|
||||
if (!run_selected_plugin(&path, tmp, newpath,
|
||||
(ndents ? dents[cur].name : NULL),
|
||||
&lastname, &lastdir)) {
|
||||
printwait(messages[MSG_FAILED], &presel);
|
||||
goto nochange;
|
||||
}
|
||||
|
||||
if (!r) {
|
||||
clearprompt();
|
||||
goto nochange;
|
||||
}
|
||||
|
||||
if (ndents)
|
||||
copycurname();
|
||||
} else {
|
||||
cfg.runplugin ^= 1;
|
||||
if (!cfg.runplugin && rundir[0]) {
|
||||
/*
|
||||
* If toggled, and still in the plugin dir,
|
||||
* switch to original directory
|
||||
*/
|
||||
if (strcmp(path, plugindir) == 0) {
|
||||
xstrlcpy(path, rundir, PATH_MAX);
|
||||
xstrlcpy(lastname, runfile, NAME_MAX);
|
||||
rundir[0] = runfile[0] = '\0';
|
||||
setdirwatch();
|
||||
goto begin;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
xstrlcpy(rundir, path, PATH_MAX);
|
||||
xstrlcpy(path, plugindir, PATH_MAX);
|
||||
if (ndents)
|
||||
xstrlcpy(runfile, dents[cur].name, NAME_MAX);
|
||||
cfg.runctx = cfg.curctx;
|
||||
lastname[0] = '\0';
|
||||
}
|
||||
setdirwatch();
|
||||
clearfilter();
|
||||
goto begin;
|
||||
case SEL_LAUNCH:
|
||||
launch_app(path, newpath);
|
||||
|
||||
|
|
14
src/nnn.h
14
src/nnn.h
|
@ -91,10 +91,10 @@ enum action {
|
|||
SEL_REMOTE,
|
||||
SEL_UMOUNT,
|
||||
SEL_HELP,
|
||||
SEL_EXEC,
|
||||
SEL_SHELL,
|
||||
SEL_PLUGKEY,
|
||||
SEL_PLUGIN,
|
||||
SEL_EXEC,
|
||||
SEL_SHELL,
|
||||
SEL_LAUNCH,
|
||||
SEL_RUNCMD,
|
||||
SEL_RUNEDIT,
|
||||
|
@ -237,17 +237,17 @@ static struct key bindings[] = {
|
|||
{ 'u', SEL_UMOUNT },
|
||||
/* Show help */
|
||||
{ '?', SEL_HELP },
|
||||
/* Execute file */
|
||||
{ 'C', SEL_EXEC },
|
||||
/* Run command */
|
||||
{ '!', SEL_SHELL },
|
||||
{ CONTROL(']'), SEL_SHELL },
|
||||
/* Plugin key */
|
||||
{ 'x', SEL_PLUGKEY },
|
||||
{ ';', SEL_PLUGKEY },
|
||||
/* Run a plugin */
|
||||
{ 'i', SEL_PLUGIN },
|
||||
{ CONTROL('V'), SEL_PLUGIN },
|
||||
/* Execute file */
|
||||
{ 'C', SEL_EXEC },
|
||||
/* Run command */
|
||||
{ '!', SEL_SHELL },
|
||||
{ CONTROL(']'), SEL_SHELL },
|
||||
/* Launcher */
|
||||
{ '=', SEL_LAUNCH },
|
||||
/* Run a command */
|
||||
|
|
Loading…
Reference in a new issue