]> Sergey Matveev's repositories - nnn.git/commitdiff
Resurrect NNN_OPENER
authorArun Prakash Jana <engineerarun@gmail.com>
Wed, 16 Jan 2019 14:41:33 +0000 (20:11 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Wed, 16 Jan 2019 14:41:33 +0000 (20:11 +0530)
README.md
nnn.1
src/nnn.c

index 6717989564410a8ea206ea96bf1307fd50c04b3d..738b87582eb5c08f12c10a3222fc162d47132cff 100644 (file)
--- a/README.md
+++ b/README.md
@@ -372,6 +372,10 @@ The following indicators are used in the detail view:
 | $PAGER | page through files (fallback less) |
 | $SHELL | spawn a shell, run script (fallback sh) |
 
+To specify a custom file opener:
+
+    export NNN_OPENER=mimeopen
+
 To edit all text files in EDITOR (preferably CLI, fallback vi):
 
     export NNN_USE_EDITOR=1
diff --git a/nnn.1 b/nnn.1
index d30e6f73ea122fa545cff983e865a370a9e942ba..41127ad99b7557928c58995bca80a6cc9ccb0e9a 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -260,6 +260,11 @@ To list the file paths copied to memory press \fIy\fR.
 The SHELL, EDITOR (VISUAL, if defined) and PAGER environment variables take precedence
 when dealing with the !, e and p commands respectively. A single combination to arguments is supported for SHELL and PAGER.
 .Pp
+\fBNNN_OPENER:\fR specify a custom file opener.
+.Bd -literal
+    export NNN_OPENER=mimeopen
+.Ed
+.Pp
 \fBNNN_BMS:\fR bookmark string as \fIkey_char:location\fR pairs (max 10) separated by
 \fI;\fR:
 .Bd -literal
index d3d09478aa1cfcbe99de638faed919e497dd09df..aaa4775cf0d2ef20bfe1c44a890321cc6c186e88 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -297,6 +297,7 @@ static char *pnamebuf, *pcopybuf;
 static int ndents, cur, total_dents = ENTRY_INCR;
 static uint idle;
 static uint idletimeout, copybufpos, copybuflen;
+static char *opener;
 static char *copier;
 static char *editor;
 static char *pager, *pager_arg;
@@ -2157,6 +2158,8 @@ static bool show_help(char *path)
                dprintf(fd, "\n");
        }
 
+       if (getenv("NNN_OPENER"))
+               dprintf(fd, "NNN_OPENER: %s\n", opener);
        if (cfg.useeditor)
                dprintf(fd, "NNN_USE_EDITOR: 1\n");
        if (getenv("NNN_CONTEXT_COLORS"))
@@ -2793,7 +2796,7 @@ nochange:
                                }
 
                                /* Invoke desktop opener as last resort */
-                               spawn(utils[OPENER], newpath, NULL, NULL, F_NOWAIT | F_NOTRACE);
+                               spawn(opener, newpath, NULL, NULL, F_NOWAIT | F_NOTRACE);
                                continue;
                        }
                        default:
@@ -3767,6 +3770,11 @@ int main(int argc, char *argv[])
        }
 #endif
 
+       /* Get custom opener, if set */
+       opener = getenv("NNN_OPENER");
+       if (!opener)
+               opener = utils[OPENER];
+
        /* Get locker wait time, if set; copier used as tmp var */
        copier = getenv("NNN_IDLE_TIMEOUT");
        if (copier) {