]> Sergey Matveev's repositories - nnn.git/commitdiff
Fix #147: support one argument to editor
authorArun Prakash Jana <engineerarun@gmail.com>
Tue, 27 Nov 2018 22:10:49 +0000 (03:40 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Tue, 27 Nov 2018 22:15:57 +0000 (03:45 +0530)
README.md
nnn.1
src/nnn.c

index 4e0c6755eb1c27640df44ecbbb5f95ec3360dc18..06669c0d4d2c6aabab17ce00c60233224c22b700 100644 (file)
--- a/README.md
+++ b/README.md
@@ -332,6 +332,8 @@ The following indicators are used in the detail view:
 - To edit all text files in EDITOR (preferably CLI, fallback vi):
 
       export NNN_USE_EDITOR=1
+      Note: Arguments to the editor should be combined together, e.g.,
+      export EDITOR='vim -xR'
 
 #### Help
 
diff --git a/nnn.1 b/nnn.1
index 6886211289658306f51251fb56ed9bb3cfa9f281..27ce89dad278483ec89532ca07f29e0f936d40f3 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -277,6 +277,10 @@ when dealing with the !, e and p commands respectively.
 files.
 .Bd -literal
     export NNN_USE_EDITOR=1
+
+    NOTE: Arguments to the editor should be combined together, e.g.,
+
+    export EDITOR='vim -xR'
 .Ed
 .Pp
 \fBNNN_IDLE_TIMEOUT:\fR set idle timeout (in seconds) to invoke terminal locker.
@@ -289,7 +293,7 @@ files.
     cat /path/to/.nnncp | xargs -0 | xsel -bi
     -----------------------------------------
 
-    Note: By default file paths are copied to the tmp file \fBDIR/.nnncp\fR, where 'DIR' (by priority) is: \fI$HOME\fR or, \fI$TMPDIR\fR or, \fI/tmp\fR.
+    NOTE: By default file paths are copied to the tmp file \fBDIR/.nnncp\fR, where 'DIR' (by priority) is: \fI$HOME\fR or, \fI$TMPDIR\fR or, \fI/tmp\fR.
 .Ed
 .Pp
 \fBNNN_SCRIPT:\fR path to a custom script to invoke with currently selected file name as argument 1.
index c673c55d95a71e1353f0197f7e95b0363a38903e..f76a68deaafd39cec615bc678605c5c0cbca795c 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -290,7 +290,7 @@ static int ndents, cur, total_dents = ENTRY_INCR;
 static uint idle;
 static uint idletimeout, copybufpos, copybuflen;
 static char *copier;
-static char *editor;
+static char *editor, *editor_arg;
 static blkcnt_t ent_blocks;
 static blkcnt_t dir_blocks;
 static ulong num_files;
@@ -2638,12 +2638,10 @@ nochange:
                                if (cfg.nonavopen && sel == SEL_NAV_IN)
                                        continue;
 
-                               /* If NNN_USE_EDITOR is set,
-                                * open text in EDITOR
-                                */
+                               /* If NNN_USE_EDITOR is set, open text in EDITOR */
                                if (editor) {
                                        if (getmime(dents[cur].name)) {
-                                               spawn(editor, newpath, NULL, path, F_NORMAL);
+                                               spawn(editor, editor_arg, newpath, path, F_NORMAL);
                                                continue;
                                        }
 
@@ -2654,7 +2652,7 @@ nochange:
                                                continue;
 
                                        if (strstr(g_buf, "text/") == g_buf) {
-                                               spawn(editor, newpath, NULL, path, F_NORMAL);
+                                               spawn(editor, editor_arg, newpath, path, F_NORMAL);
                                                continue;
                                        }
                                }
@@ -3545,6 +3543,18 @@ int main(int argc, char *argv[])
                editor = xgetenv("VISUAL", NULL);
                if (!editor)
                        editor = xgetenv("EDITOR", "vi");
+               if (editor) {
+                       /* copier used as a temp var */
+                       copier = editor;
+                       while (*copier) {
+                               if (*copier == ' ') {
+                                       *copier = '\0';
+                                       editor_arg = ++copier;
+                                       break;
+                               }
+                               ++copier;
+                       }
+               }
        }
 
        /* Get locker wait time, if set; copier used as tmp var */