src/nnn.c | 21 +++++++++++++++++++++ diff --git a/src/nnn.c b/src/nnn.c index 51d17940b5eca5c817bb20f531a365fd7ac1272e..c94ecbe5b761d6ff731264ab24d921ce5b3201c6 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -4360,6 +4360,10 @@ if (!setup_config()) return 1; + /* Get custom opener, if set */ + opener = xgetenv(env_cfg[NNN_OPENER], utils[OPENER]); + DPRINTF_S(opener); + /* Parse bookmarks string */ if (!parsebmstr()) { fprintf(stderr, "%s\n", env_cfg[NNN_BMS]); @@ -4386,6 +4390,23 @@ DPRINTF_S(initpath); if (!initpath) { 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(initpath, &sb) == -1) { + xerror(); + return 1; + } + + if (S_ISREG(sb.st_mode)) { + execlp(opener, opener, arg, NULL); + return 0; } }