mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Handle argument ordering in spawn()
This commit is contained in:
parent
82a58800d3
commit
b59a21b57e
|
@ -117,7 +117,7 @@ We need contributors. Please visit the ToDo list.
|
||||||
- Run custom scripts in the current directory
|
- Run custom scripts in the current directory
|
||||||
- Change directory at exit (*easy* shell integration)
|
- Change directory at exit (*easy* shell integration)
|
||||||
- Edit file in EDITOR or open in PAGER
|
- Edit file in EDITOR or open in PAGER
|
||||||
- GUI app launcher (up to 2 space-separated args)
|
- GUI app launcher
|
||||||
- Terminal locker integration
|
- Terminal locker integration
|
||||||
- Unicode support
|
- Unicode support
|
||||||
- Highly optimized, static analysis integrated code
|
- Highly optimized, static analysis integrated code
|
||||||
|
@ -348,6 +348,8 @@ Arguments to the `$EDITOR`, `$PAGER` and `$SHELL` should be combined together, e
|
||||||
|
|
||||||
export EDITOR='vim -xR'
|
export EDITOR='vim -xR'
|
||||||
|
|
||||||
|
The option `open with` takes 1 combined argument and `launcher` takes 2.
|
||||||
|
|
||||||
#### Help
|
#### Help
|
||||||
|
|
||||||
$ nnn -h
|
$ nnn -h
|
||||||
|
|
4
nnn.1
4
nnn.1
|
@ -90,7 +90,7 @@ FILES
|
||||||
.Pp
|
.Pp
|
||||||
.Bl -tag -width "l, [Right], [Return] or C-mXXXX" -offset indent -compact
|
.Bl -tag -width "l, [Right], [Return] or C-mXXXX" -offset indent -compact
|
||||||
.It Ic ^O
|
.It Ic ^O
|
||||||
Open with an application
|
Open with an application (takes 1 combined argument)
|
||||||
.It Ic n
|
.It Ic n
|
||||||
Create a new file or directory
|
Create a new file or directory
|
||||||
.It Ic D
|
.It Ic D
|
||||||
|
@ -144,7 +144,7 @@ MISC
|
||||||
.Pp
|
.Pp
|
||||||
.Bl -tag -width "l, [Right], [Return] or C-mXXXX" -offset indent -compact
|
.Bl -tag -width "l, [Right], [Return] or C-mXXXX" -offset indent -compact
|
||||||
.It Ic o
|
.It Ic o
|
||||||
Launch a GUI application
|
Launch a GUI application (takes 2 combined arguments)
|
||||||
.It Ic \&!, ^]
|
.It Ic \&!, ^]
|
||||||
Spawn SHELL in current directory (fallback sh)
|
Spawn SHELL in current directory (fallback sh)
|
||||||
.It Ic R
|
.It Ic R
|
||||||
|
|
26
src/nnn.c
26
src/nnn.c
|
@ -812,10 +812,17 @@ static void initcurses(void)
|
||||||
*/
|
*/
|
||||||
static void spawn(const char *file, const char *arg1, const char *arg2, const char *dir, uchar flag)
|
static void spawn(const char *file, const char *arg1, const char *arg2, const char *dir, uchar flag)
|
||||||
{
|
{
|
||||||
static char *shlvl;
|
static const char *shlvl;
|
||||||
static pid_t pid;
|
static pid_t pid;
|
||||||
static int status;
|
static int status;
|
||||||
|
|
||||||
|
/* Swap args if the first arg is NULL and second isn't */
|
||||||
|
if (!arg1 && arg2) {
|
||||||
|
shlvl = arg1;
|
||||||
|
arg1 = arg2;
|
||||||
|
arg2 = shlvl;
|
||||||
|
}
|
||||||
|
|
||||||
if (flag & F_NORMAL)
|
if (flag & F_NORMAL)
|
||||||
exitcurses();
|
exitcurses();
|
||||||
|
|
||||||
|
@ -2682,7 +2689,7 @@ nochange:
|
||||||
if (cfg.useeditor &&
|
if (cfg.useeditor &&
|
||||||
get_output(g_buf, CMD_LEN_MAX, "file", FILE_OPTS, newpath, FALSE) &&
|
get_output(g_buf, CMD_LEN_MAX, "file", FILE_OPTS, newpath, FALSE) &&
|
||||||
strstr(g_buf, "text/") == g_buf) {
|
strstr(g_buf, "text/") == g_buf) {
|
||||||
spawn(editor, newpath, editor_arg, path, F_NORMAL);
|
spawn(editor, editor_arg, newpath, path, F_NORMAL);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3192,6 +3199,9 @@ nochange:
|
||||||
break; // fallthrough
|
break; // fallthrough
|
||||||
case SEL_LAUNCH: // fallthrough
|
case SEL_LAUNCH: // fallthrough
|
||||||
case SEL_NEW:
|
case SEL_NEW:
|
||||||
|
{
|
||||||
|
char *ptr = NULL, *ptr1 = NULL, *ptr2 = NULL;
|
||||||
|
|
||||||
if (sel == SEL_OPEN)
|
if (sel == SEL_OPEN)
|
||||||
tmp = xreadline(NULL, "open with: ");
|
tmp = xreadline(NULL, "open with: ");
|
||||||
else if (sel == SEL_LAUNCH)
|
else if (sel == SEL_LAUNCH)
|
||||||
|
@ -3218,17 +3228,18 @@ nochange:
|
||||||
else
|
else
|
||||||
r = F_NOWAIT | F_NOTRACE;
|
r = F_NOWAIT | F_NOTRACE;
|
||||||
|
|
||||||
|
getprogarg(tmp, &ptr);
|
||||||
mkpath(path, dents[cur].name, newpath, PATH_MAX);
|
mkpath(path, dents[cur].name, newpath, PATH_MAX);
|
||||||
spawn(tmp, newpath, NULL, path, r);
|
spawn(tmp, ptr, newpath, path, r);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sel == SEL_LAUNCH) {
|
if (sel == SEL_LAUNCH) {
|
||||||
uint args = 0;
|
uint args = 0;
|
||||||
char *ptr = tmp, *ptr1 = NULL, *ptr2 = NULL;
|
ptr = tmp;
|
||||||
|
|
||||||
while (*ptr) {
|
while (*ptr) {
|
||||||
if (*ptr == ' ') {
|
if (isblank(*ptr)) {
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
if (args == 0)
|
if (args == 0)
|
||||||
ptr1 = ptr + 1;
|
ptr1 = ptr + 1;
|
||||||
|
@ -3301,6 +3312,7 @@ nochange:
|
||||||
close(fd);
|
close(fd);
|
||||||
xstrlcpy(lastname, tmp, NAME_MAX + 1);
|
xstrlcpy(lastname, tmp, NAME_MAX + 1);
|
||||||
goto begin;
|
goto begin;
|
||||||
|
}
|
||||||
case SEL_RENAME:
|
case SEL_RENAME:
|
||||||
if (!ndents)
|
if (!ndents)
|
||||||
break;
|
break;
|
||||||
|
@ -3402,10 +3414,10 @@ nochange:
|
||||||
/* Repopulate as directory content may have changed */
|
/* Repopulate as directory content may have changed */
|
||||||
goto begin;
|
goto begin;
|
||||||
case SEL_RUNEDIT:
|
case SEL_RUNEDIT:
|
||||||
spawn(editor, dents[cur].name, editor_arg, path, F_NORMAL);
|
spawn(editor, editor_arg, dents[cur].name, path, F_NORMAL);
|
||||||
break;
|
break;
|
||||||
case SEL_RUNPAGE:
|
case SEL_RUNPAGE:
|
||||||
spawn(pager, dents[cur].name, pager_arg, path, F_NORMAL);
|
spawn(pager, pager_arg, dents[cur].name, 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);
|
||||||
|
|
Loading…
Reference in a new issue