Fix #147: support one argument to editor

This commit is contained in:
Arun Prakash Jana 2018-11-28 03:40:49 +05:30
parent 0a21d90ad5
commit c0b9703831
No known key found for this signature in database
GPG key ID: A75979F35C080412
3 changed files with 23 additions and 7 deletions

View file

@ -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

6
nnn.1
View file

@ -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.

View file

@ -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 */