mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 20:01:27 +00:00
Fix #157: support one combined arg for EDITOR, PAGER and SHELL
This commit is contained in:
parent
d7da4acde0
commit
4b9796eae0
|
@ -330,10 +330,12 @@ The following indicators are used in the detail view:
|
||||||
| $PAGER | page through files (fallback less) |
|
| $PAGER | page through files (fallback less) |
|
||||||
| $SHELL | spawn a shell, run script (fallback sh) |
|
| $SHELL | spawn a shell, run script (fallback sh) |
|
||||||
|
|
||||||
- To edit all text files in EDITOR (preferably CLI, fallback vi):
|
To edit all text files in EDITOR (preferably CLI, fallback vi):
|
||||||
|
|
||||||
export NNN_USE_EDITOR=1
|
export NNN_USE_EDITOR=1
|
||||||
Note: Arguments to the editor should be combined together, e.g.,
|
|
||||||
|
Arguments to the `$EDITOR`, `$PAGER` and `$SHELL` should be combined together, e.g.,
|
||||||
|
|
||||||
export EDITOR='vim -xR'
|
export EDITOR='vim -xR'
|
||||||
|
|
||||||
#### Help
|
#### Help
|
||||||
|
|
23
src/nnn.c
23
src/nnn.c
|
@ -293,6 +293,7 @@ static uint idletimeout, copybufpos, copybuflen;
|
||||||
static char *copier;
|
static char *copier;
|
||||||
static char *editor, *editor_arg;
|
static char *editor, *editor_arg;
|
||||||
static char *pager, *pager_arg;
|
static char *pager, *pager_arg;
|
||||||
|
static char *shell, *shell_arg;
|
||||||
static blkcnt_t ent_blocks;
|
static blkcnt_t ent_blocks;
|
||||||
static blkcnt_t dir_blocks;
|
static blkcnt_t dir_blocks;
|
||||||
static ulong num_files;
|
static ulong num_files;
|
||||||
|
@ -872,7 +873,7 @@ static void getprogarg(char *prog, char **arg)
|
||||||
{
|
{
|
||||||
char *argptr;
|
char *argptr;
|
||||||
|
|
||||||
while (*prog && *prog != ' ')
|
while (*prog && !isblank(*prog))
|
||||||
++prog;
|
++prog;
|
||||||
|
|
||||||
if (*prog) {
|
if (*prog) {
|
||||||
|
@ -882,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 (isblank(*argptr)) {
|
||||||
fprintf(stderr, "Too many args [%s]\n", prog);
|
fprintf(stderr, "Too many args [%s]\n", prog);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -2115,15 +2116,15 @@ static int show_help(char *path)
|
||||||
if (getenv("PWD"))
|
if (getenv("PWD"))
|
||||||
dprintf(fd, "PWD: %s\n", getenv("PWD"));
|
dprintf(fd, "PWD: %s\n", getenv("PWD"));
|
||||||
if (getenv("SHELL"))
|
if (getenv("SHELL"))
|
||||||
dprintf(fd, "SHELL: %s\n", getenv("SHELL"));
|
dprintf(fd, "SHELL: %s\n", shell);
|
||||||
if (getenv("SHLVL"))
|
if (getenv("SHLVL"))
|
||||||
dprintf(fd, "SHLVL: %s\n", getenv("SHLVL"));
|
dprintf(fd, "SHLVL: %s\n", getenv("SHLVL"));
|
||||||
if (getenv("VISUAL"))
|
if (getenv("VISUAL"))
|
||||||
dprintf(fd, "VISUAL: %s\n", getenv("VISUAL"));
|
dprintf(fd, "VISUAL: %s\n", editor);
|
||||||
else if (getenv("EDITOR"))
|
else if (getenv("EDITOR"))
|
||||||
dprintf(fd, "EDITOR: %s\n", getenv("EDITOR"));
|
dprintf(fd, "EDITOR: %s\n", editor);
|
||||||
if (getenv("PAGER"))
|
if (getenv("PAGER"))
|
||||||
dprintf(fd, "PAGER: %s\n", getenv("PAGER"));
|
dprintf(fd, "PAGER: %s\n", pager);
|
||||||
|
|
||||||
dprintf(fd, "\nVersion: %s\n%s\n", VERSION, GENERAL_INFO);
|
dprintf(fd, "\nVersion: %s\n%s\n", VERSION, GENERAL_INFO);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
@ -3351,8 +3352,6 @@ nochange:
|
||||||
break;
|
break;
|
||||||
case SEL_RUN: // fallthrough
|
case SEL_RUN: // fallthrough
|
||||||
case SEL_RUNSCRIPT:
|
case SEL_RUNSCRIPT:
|
||||||
run = xgetenv(env, run);
|
|
||||||
|
|
||||||
if (sel == SEL_RUNSCRIPT) {
|
if (sel == SEL_RUNSCRIPT) {
|
||||||
tmp = getenv("NNN_SCRIPT");
|
tmp = getenv("NNN_SCRIPT");
|
||||||
if (tmp) {
|
if (tmp) {
|
||||||
|
@ -3371,11 +3370,11 @@ nochange:
|
||||||
if (ndents)
|
if (ndents)
|
||||||
curfile = dents[cur].name;
|
curfile = dents[cur].name;
|
||||||
|
|
||||||
spawn(run, tmp, curfile, path, F_NORMAL | F_SIGINT);
|
spawn(shell, tmp, curfile, path, F_NORMAL | F_SIGINT);
|
||||||
} else
|
} else
|
||||||
printmsg("set NNN_SCRIPT");
|
printmsg("set NNN_SCRIPT");
|
||||||
} else {
|
} else {
|
||||||
spawn(run, NULL, NULL, path, F_NORMAL | F_MARKER);
|
spawn(shell, shell_arg, NULL, path, F_NORMAL | F_MARKER);
|
||||||
|
|
||||||
/* Continue in navigate-as-you-type mode, if enabled */
|
/* Continue in navigate-as-you-type mode, if enabled */
|
||||||
if (cfg.filtermode)
|
if (cfg.filtermode)
|
||||||
|
@ -3600,6 +3599,10 @@ int main(int argc, char *argv[])
|
||||||
pager = xgetenv("PAGER", "less");
|
pager = xgetenv("PAGER", "less");
|
||||||
getprogarg(pager, &pager_arg);
|
getprogarg(pager, &pager_arg);
|
||||||
|
|
||||||
|
/* Get SHELL */
|
||||||
|
shell = xgetenv("SHELL", "sh");
|
||||||
|
getprogarg(shell, &shell_arg);
|
||||||
|
|
||||||
#ifdef LINUX_INOTIFY
|
#ifdef LINUX_INOTIFY
|
||||||
/* Initialize inotify */
|
/* Initialize inotify */
|
||||||
inotify_fd = inotify_init1(IN_NONBLOCK);
|
inotify_fd = inotify_init1(IN_NONBLOCK);
|
||||||
|
|
|
@ -222,10 +222,10 @@ static struct key bindings[] = {
|
||||||
/* Show help */
|
/* Show help */
|
||||||
{ '?', SEL_HELP, "", "" },
|
{ '?', SEL_HELP, "", "" },
|
||||||
/* Run command */
|
/* Run command */
|
||||||
{ '!', SEL_RUN, "sh", "SHELL" },
|
{ '!', SEL_RUN, "", "" },
|
||||||
{ CONTROL(']'), SEL_RUN, "sh", "SHELL" },
|
{ CONTROL(']'), SEL_RUN, "", "" },
|
||||||
/* Run a custom script */
|
/* Run a custom script */
|
||||||
{ 'R', SEL_RUNSCRIPT, "sh", "SHELL" },
|
{ 'R', SEL_RUNSCRIPT, "", "" },
|
||||||
/* Run command with argument */
|
/* Run command with argument */
|
||||||
{ 'e', SEL_RUNEDIT, "", "" },
|
{ 'e', SEL_RUNEDIT, "", "" },
|
||||||
{ 'p', SEL_RUNPAGE, "", "" },
|
{ 'p', SEL_RUNPAGE, "", "" },
|
||||||
|
|
Loading…
Reference in a new issue