aboutsummaryrefslogtreecommitdiffstats
path: root/src/nnn.c
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-04-16 22:55:59 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-04-16 22:55:59 +0530
commit39035bd75c56e9e20f988cfab7afd87996cfd91a (patch)
tree210f6d93efa6e14cd862e13a8bc7dd5a093e59fc /src/nnn.c
parentc5b5181ac42f8b81a44968dbd92cae8a2352030b (diff)
downloadnnn-39035bd75c56e9e20f988cfab7afd87996cfd91a.tar.gz
nnn as file manager: more changes
1. Support passing files to nnn 2. Enable debug logs much early
Diffstat (limited to 'src/nnn.c')
-rw-r--r--src/nnn.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/src/nnn.c b/src/nnn.c
index c11aa23..72db2c5 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -4045,9 +4045,20 @@ int main(int argc, char *argv[])
++opt;
}
+#ifdef DBGMODE
+ enabledbg();
+ atexit(disabledbg);
+#endif
+
home = getenv("HOME");
DPRINTF_S(home);
+ /* Get custom opener, if set */
+ opener = xgetenv(env_cfg[NNN_OPENER], utils[OPENER]);
+ if (getenv(env_cfg[NNN_OPENER_DETACH]))
+ opener_flag |= F_NOWAIT;
+ DPRINTF_S(opener);
+
/* Parse bookmarks string */
if (!parsebmstr()) {
fprintf(stderr, "%s\n", env_cfg[NNN_BMS]);
@@ -4072,10 +4083,28 @@ int main(int argc, char *argv[])
&& ipath[3] == 'e' && ipath[4] == ':' && ipath[5] == '/' && ipath[6] == '/')
ipath = ipath + 7;
ipath = realpath(ipath, cwd);
+ DPRINTF_S(ipath);
if (!ipath) {
xerror();
return 1;
}
+
+ /*
+ * If nnn is set as the file manager, applications may try to open
+ * files by invoking nnn. In that case pass the file path to the
+ * desktop opener and exit.
+ */
+ struct stat sb;
+
+ if (stat(ipath, &sb) == -1) {
+ printwarn();
+ return 1;
+ }
+
+ if (S_ISREG(sb.st_mode)) {
+ spawn(opener, ipath, NULL, NULL, opener_flag);
+ return 0;
+ }
}
/* Edit text in EDITOR, if opted */
@@ -4113,12 +4142,6 @@ int main(int argc, char *argv[])
}
#endif
- /* Get custom opener, if set */
- opener = xgetenv(env_cfg[NNN_OPENER], utils[OPENER]);
- if (getenv(env_cfg[NNN_OPENER_DETACH]))
- opener_flag |= F_NOWAIT;
- DPRINTF_S(opener);
-
/* Set nnn nesting level, idletimeout used as tmp var */
idletimeout = xatoi(getenv(env_cfg[NNNLVL]));
setenv(env_cfg[NNNLVL], xitoa(++idletimeout), 1);
@@ -4200,9 +4223,6 @@ int main(int argc, char *argv[])
read_history(NULL);
#endif
-#ifdef DBGMODE
- enabledbg();
-#endif
if (!initcurses())
return 1;
@@ -4236,8 +4256,5 @@ int main(int argc, char *argv[])
close(kq);
#endif
-#ifdef DBGMODE
- disabledbg();
-#endif
return 0;
}