mirror of https://github.com/jarun/nnn.git
Clean up plugin handling code
This commit is contained in:
parent
62457c3984
commit
ae7a3fbdc1
53
src/nnn.c
53
src/nnn.c
|
@ -3264,6 +3264,27 @@ static void show_help(const char *path)
|
||||||
unlink(g_tmpfpath);
|
unlink(g_tmpfpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool run_selected_plugin(char *path, const char *file, char *newpath, char *rundir, char *runfile, char *lastname)
|
||||||
|
{
|
||||||
|
if ((cfg.runctx != cfg.curctx)
|
||||||
|
/* Must be in plugin directory to select plugin */
|
||||||
|
|| (strcmp(path, plugindir) != 0))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
mkpath(path, file, newpath);
|
||||||
|
/* Copy to path so we can return back to earlier dir */
|
||||||
|
xstrlcpy(path, rundir, PATH_MAX);
|
||||||
|
if (runfile[0]) {
|
||||||
|
xstrlcpy(lastname, runfile, NAME_MAX);
|
||||||
|
spawn(newpath, lastname, path, path, F_NORMAL);
|
||||||
|
runfile[0] = '\0';
|
||||||
|
} else
|
||||||
|
spawn(newpath, NULL, path, path, F_NORMAL);
|
||||||
|
rundir[0] = '\0';
|
||||||
|
cfg.runplugin = 0;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static int sum_bsizes(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
|
static int sum_bsizes(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
|
||||||
{
|
{
|
||||||
(void) fpath;
|
(void) fpath;
|
||||||
|
@ -4029,22 +4050,8 @@ nochange:
|
||||||
|
|
||||||
/* Handle plugin selection mode */
|
/* Handle plugin selection mode */
|
||||||
if (cfg.runplugin) {
|
if (cfg.runplugin) {
|
||||||
if (!plugindir || (cfg.runctx != cfg.curctx)
|
if (!run_selected_plugin(path, dents[cur].name, newpath, rundir, runfile, lastname))
|
||||||
/* Must be in plugin directory to select plugin */
|
|
||||||
|| (strcmp(path, plugindir) != 0))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
mkpath(path, dents[cur].name, newpath);
|
|
||||||
/* Copy to path so we can return back to earlier dir */
|
|
||||||
xstrlcpy(path, rundir, PATH_MAX);
|
|
||||||
if (runfile[0]) {
|
|
||||||
xstrlcpy(lastname, runfile, NAME_MAX);
|
|
||||||
spawn(newpath, lastname, path, path, F_NORMAL);
|
|
||||||
runfile[0] = '\0';
|
|
||||||
} else
|
|
||||||
spawn(newpath, NULL, path, path, F_NORMAL);
|
|
||||||
rundir[0] = '\0';
|
|
||||||
cfg.runplugin = 0;
|
|
||||||
setdirwatch();
|
setdirwatch();
|
||||||
goto begin;
|
goto begin;
|
||||||
}
|
}
|
||||||
|
@ -4841,20 +4848,12 @@ nochange:
|
||||||
break;
|
break;
|
||||||
case SEL_PLUGKEY: // fallthrough
|
case SEL_PLUGKEY: // fallthrough
|
||||||
case SEL_PLUGIN:
|
case SEL_PLUGIN:
|
||||||
if (!plugindir) {
|
/* Check if directory is accessible */
|
||||||
printwait("plugins dir missing", &presel);
|
if (!xdiraccess(plugindir)) {
|
||||||
goto nochange;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stat(plugindir, &sb) == -1) {
|
|
||||||
printwarn(&presel);
|
printwarn(&presel);
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Must be a directory */
|
|
||||||
if (!S_ISDIR(sb.st_mode))
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (sel == SEL_PLUGKEY)
|
if (sel == SEL_PLUGKEY)
|
||||||
{
|
{
|
||||||
r = get_input("");
|
r = get_input("");
|
||||||
|
@ -4889,10 +4888,6 @@ nochange:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if directory is accessible */
|
|
||||||
if (!xdiraccess(plugindir))
|
|
||||||
goto nochange;
|
|
||||||
|
|
||||||
xstrlcpy(rundir, path, PATH_MAX);
|
xstrlcpy(rundir, path, PATH_MAX);
|
||||||
xstrlcpy(path, plugindir, PATH_MAX);
|
xstrlcpy(path, plugindir, PATH_MAX);
|
||||||
if (ndents)
|
if (ndents)
|
||||||
|
|
Loading…
Reference in New Issue