aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-10-19 07:00:04 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-10-19 07:00:04 +0530
commitae7a3fbdc1ae4f335b6c42a4b65b0394972c5844 (patch)
tree9597c50e14799773a51cb13a9c2ca9f76958c0d8 /src
parent62457c39847233e5ccf92772fe088bcf737f2089 (diff)
downloadnnn-ae7a3fbdc1ae4f335b6c42a4b65b0394972c5844.tar.gz
Clean up plugin handling code
Diffstat (limited to 'src')
-rw-r--r--src/nnn.c53
1 files changed, 24 insertions, 29 deletions
diff --git a/src/nnn.c b/src/nnn.c
index 91343d9..89ab55a 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -3264,6 +3264,27 @@ static void show_help(const char *path)
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)
{
(void) fpath;
@@ -4029,22 +4050,8 @@ nochange:
/* Handle plugin selection mode */
if (cfg.runplugin) {
- if (!plugindir || (cfg.runctx != cfg.curctx)
- /* Must be in plugin directory to select plugin */
- || (strcmp(path, plugindir) != 0))
+ if (!run_selected_plugin(path, dents[cur].name, newpath, rundir, runfile, lastname))
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();
goto begin;
}
@@ -4841,20 +4848,12 @@ nochange:
break;
case SEL_PLUGKEY: // fallthrough
case SEL_PLUGIN:
- if (!plugindir) {
- printwait("plugins dir missing", &presel);
- goto nochange;
- }
-
- if (stat(plugindir, &sb) == -1) {
+ /* Check if directory is accessible */
+ if (!xdiraccess(plugindir)) {
printwarn(&presel);
goto nochange;
}
- /* Must be a directory */
- if (!S_ISDIR(sb.st_mode))
- break;
-
if (sel == SEL_PLUGKEY)
{
r = get_input("");
@@ -4889,10 +4888,6 @@ nochange:
break;
}
- /* Check if directory is accessible */
- if (!xdiraccess(plugindir))
- goto nochange;
-
xstrlcpy(rundir, path, PATH_MAX);
xstrlcpy(path, plugindir, PATH_MAX);
if (ndents)