/* Make sure there are no more args */
while (*argptr) {
if (*argptr == ' ') {
- fprintf(stderr, "Too many %s args\n", prog);
+ fprintf(stderr, "Too many args [%s]\n", prog);
exit(1);
}
++argptr;
}
if (cfg.useeditor)
- dprintf(fd, "NNN_USE_EDITOR: %s\n", editor);
+ dprintf(fd, "NNN_USE_EDITOR: 1\n");
if (idletimeout)
dprintf(fd, "NNN_IDLE_TIMEOUT: %d secs\n", idletimeout);
if (copier)
continue;
/* If NNN_USE_EDITOR is set, open text in EDITOR */
- if (cfg.useeditor) {
- if (getmime(dents[cur].name)) {
+ if (cfg.useeditor)
+ if (getmime(dents[cur].name) ||
+ (get_output(g_buf, MAX_CMD_LEN, "file", FILE_OPTS, newpath, 0) &&
+ strstr(g_buf, "text/") == g_buf)) {
spawn(editor, newpath, editor_arg, path, F_NORMAL);
continue;
}
- /* Recognize and open plain
- * text files with vi
- */
- if (get_output(g_buf, MAX_CMD_LEN, "file", FILE_OPTS, newpath, 0) == NULL)
- continue;
-
- if (strstr(g_buf, "text/") == g_buf) {
- spawn(editor, newpath, editor_arg, path, F_NORMAL);
- continue;
- }
- }
-
/* Invoke desktop opener as last resort */
spawn(utils[OPENER], newpath, NULL, NULL, F_NOWAIT | F_NOTRACE);
continue;
/* Repopulate as directory content may have changed */
goto begin;
- case SEL_RUNARG:
- tmp = NULL;
- run = xgetenv(env, run);
- if ((!run || !run[0]) && (strcmp("VISUAL", env) == 0)) {
- run = editor;
- tmp = editor_arg;
- }
- spawn(run, dents[cur].name, tmp, path, F_NORMAL);
+ case SEL_RUNEDIT:
+ spawn(editor, dents[cur].name, editor_arg, path, F_NORMAL);
+ break;
+ case SEL_RUNPAGE:
+ spawn(pager, dents[cur].name, pager_arg, path, F_NORMAL);
break;
case SEL_LOCK:
spawn(utils[LOCKER], NULL, NULL, NULL, F_NORMAL | F_SIGINT);
if (getuid() == 0 || getenv("NNN_SHOW_HIDDEN"))
cfg.showhidden = 1;
+ /* Edit text in EDITOR, if opted */
+ if (getenv("NNN_USE_EDITOR"))
+ cfg.useeditor = 1;
+
/* Get VISUAL/EDITOR */
editor = xgetenv("VISUAL", xgetenv("EDITOR", "vi"));
getprogarg(editor, &editor_arg);
pager = xgetenv("PAGER", "less");
getprogarg(pager, &pager_arg);
- /* Edit text in EDITOR, if opted */
- if (getenv("NNN_USE_EDITOR"))
- cfg.useeditor = 1;
-
#ifdef LINUX_INOTIFY
/* Initialize inotify */
inotify_fd = inotify_init1(IN_NONBLOCK);
SEL_HELP,
SEL_RUN,
SEL_RUNSCRIPT,
- SEL_RUNARG,
+ SEL_RUNEDIT,
+ SEL_RUNPAGE,
SEL_LOCK,
SEL_QUITCTX,
SEL_QUITCD,
/* Run a custom script */
{ 'R', SEL_RUNSCRIPT, "sh", "SHELL" },
/* Run command with argument */
- { 'e', SEL_RUNARG, "", "VISUAL" },
- { 'p', SEL_RUNARG, "", "PAGER" },
+ { 'e', SEL_RUNEDIT, "", "" },
+ { 'p', SEL_RUNPAGE, "", "" },
/* Lock screen */
{ 'L', SEL_LOCK, "", "" },
/* Quit a context */