mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 13:51:31 +00:00
Split EDITOR & PAGER options, concise NNN_USE_EDITOR logic.
This commit is contained in:
parent
08bd6f1bcb
commit
d7da4acde0
43
src/nnn.c
43
src/nnn.c
|
@ -883,7 +883,7 @@ static void getprogarg(char *prog, char **arg)
|
||||||
/* Make sure there are no more args */
|
/* Make sure there are no more args */
|
||||||
while (*argptr) {
|
while (*argptr) {
|
||||||
if (*argptr == ' ') {
|
if (*argptr == ' ') {
|
||||||
fprintf(stderr, "Too many %s args\n", prog);
|
fprintf(stderr, "Too many args [%s]\n", prog);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
++argptr;
|
++argptr;
|
||||||
|
@ -2092,7 +2092,7 @@ static int show_help(char *path)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg.useeditor)
|
if (cfg.useeditor)
|
||||||
dprintf(fd, "NNN_USE_EDITOR: %s\n", editor);
|
dprintf(fd, "NNN_USE_EDITOR: 1\n");
|
||||||
if (idletimeout)
|
if (idletimeout)
|
||||||
dprintf(fd, "NNN_IDLE_TIMEOUT: %d secs\n", idletimeout);
|
dprintf(fd, "NNN_IDLE_TIMEOUT: %d secs\n", idletimeout);
|
||||||
if (copier)
|
if (copier)
|
||||||
|
@ -2694,24 +2694,14 @@ nochange:
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* If NNN_USE_EDITOR is set, open text in EDITOR */
|
/* If NNN_USE_EDITOR is set, open text in EDITOR */
|
||||||
if (cfg.useeditor) {
|
if (cfg.useeditor)
|
||||||
if (getmime(dents[cur].name)) {
|
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);
|
spawn(editor, newpath, editor_arg, path, F_NORMAL);
|
||||||
continue;
|
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 */
|
/* Invoke desktop opener as last resort */
|
||||||
spawn(utils[OPENER], newpath, NULL, NULL, F_NOWAIT | F_NOTRACE);
|
spawn(utils[OPENER], newpath, NULL, NULL, F_NOWAIT | F_NOTRACE);
|
||||||
continue;
|
continue;
|
||||||
|
@ -3398,14 +3388,11 @@ nochange:
|
||||||
|
|
||||||
/* Repopulate as directory content may have changed */
|
/* Repopulate as directory content may have changed */
|
||||||
goto begin;
|
goto begin;
|
||||||
case SEL_RUNARG:
|
case SEL_RUNEDIT:
|
||||||
tmp = NULL;
|
spawn(editor, dents[cur].name, editor_arg, path, F_NORMAL);
|
||||||
run = xgetenv(env, run);
|
break;
|
||||||
if ((!run || !run[0]) && (strcmp("VISUAL", env) == 0)) {
|
case SEL_RUNPAGE:
|
||||||
run = editor;
|
spawn(pager, dents[cur].name, pager_arg, path, F_NORMAL);
|
||||||
tmp = editor_arg;
|
|
||||||
}
|
|
||||||
spawn(run, dents[cur].name, tmp, path, F_NORMAL);
|
|
||||||
break;
|
break;
|
||||||
case SEL_LOCK:
|
case SEL_LOCK:
|
||||||
spawn(utils[LOCKER], NULL, NULL, NULL, F_NORMAL | F_SIGINT);
|
spawn(utils[LOCKER], NULL, NULL, NULL, F_NORMAL | F_SIGINT);
|
||||||
|
@ -3601,6 +3588,10 @@ int main(int argc, char *argv[])
|
||||||
if (getuid() == 0 || getenv("NNN_SHOW_HIDDEN"))
|
if (getuid() == 0 || getenv("NNN_SHOW_HIDDEN"))
|
||||||
cfg.showhidden = 1;
|
cfg.showhidden = 1;
|
||||||
|
|
||||||
|
/* Edit text in EDITOR, if opted */
|
||||||
|
if (getenv("NNN_USE_EDITOR"))
|
||||||
|
cfg.useeditor = 1;
|
||||||
|
|
||||||
/* Get VISUAL/EDITOR */
|
/* Get VISUAL/EDITOR */
|
||||||
editor = xgetenv("VISUAL", xgetenv("EDITOR", "vi"));
|
editor = xgetenv("VISUAL", xgetenv("EDITOR", "vi"));
|
||||||
getprogarg(editor, &editor_arg);
|
getprogarg(editor, &editor_arg);
|
||||||
|
@ -3609,10 +3600,6 @@ int main(int argc, char *argv[])
|
||||||
pager = xgetenv("PAGER", "less");
|
pager = xgetenv("PAGER", "less");
|
||||||
getprogarg(pager, &pager_arg);
|
getprogarg(pager, &pager_arg);
|
||||||
|
|
||||||
/* Edit text in EDITOR, if opted */
|
|
||||||
if (getenv("NNN_USE_EDITOR"))
|
|
||||||
cfg.useeditor = 1;
|
|
||||||
|
|
||||||
#ifdef LINUX_INOTIFY
|
#ifdef LINUX_INOTIFY
|
||||||
/* Initialize inotify */
|
/* Initialize inotify */
|
||||||
inotify_fd = inotify_init1(IN_NONBLOCK);
|
inotify_fd = inotify_init1(IN_NONBLOCK);
|
||||||
|
|
|
@ -82,7 +82,8 @@ enum action {
|
||||||
SEL_HELP,
|
SEL_HELP,
|
||||||
SEL_RUN,
|
SEL_RUN,
|
||||||
SEL_RUNSCRIPT,
|
SEL_RUNSCRIPT,
|
||||||
SEL_RUNARG,
|
SEL_RUNEDIT,
|
||||||
|
SEL_RUNPAGE,
|
||||||
SEL_LOCK,
|
SEL_LOCK,
|
||||||
SEL_QUITCTX,
|
SEL_QUITCTX,
|
||||||
SEL_QUITCD,
|
SEL_QUITCD,
|
||||||
|
@ -226,8 +227,8 @@ static struct key bindings[] = {
|
||||||
/* Run a custom script */
|
/* Run a custom script */
|
||||||
{ 'R', SEL_RUNSCRIPT, "sh", "SHELL" },
|
{ 'R', SEL_RUNSCRIPT, "sh", "SHELL" },
|
||||||
/* Run command with argument */
|
/* Run command with argument */
|
||||||
{ 'e', SEL_RUNARG, "", "VISUAL" },
|
{ 'e', SEL_RUNEDIT, "", "" },
|
||||||
{ 'p', SEL_RUNARG, "", "PAGER" },
|
{ 'p', SEL_RUNPAGE, "", "" },
|
||||||
/* Lock screen */
|
/* Lock screen */
|
||||||
{ 'L', SEL_LOCK, "", "" },
|
{ 'L', SEL_LOCK, "", "" },
|
||||||
/* Quit a context */
|
/* Quit a context */
|
||||||
|
|
Loading…
Reference in a new issue