mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Support run a command
This commit is contained in:
parent
80dea7be49
commit
e7b1215a20
|
@ -116,6 +116,7 @@ We need contributors. Please visit the ToDo list.
|
||||||
- Batch rename/move/delete (needs vidir)
|
- Batch rename/move/delete (needs vidir)
|
||||||
- Show directories in custom color (default: blue)
|
- Show directories in custom color (default: blue)
|
||||||
- Spawn a subshell in the current directory
|
- Spawn a subshell in the current directory
|
||||||
|
- Run a command
|
||||||
- Run custom scripts in the current directory
|
- Run custom scripts in the current directory
|
||||||
- Run current file as executable
|
- Run current file as executable
|
||||||
- Change directory at exit (*easy* shell integration)
|
- Change directory at exit (*easy* shell integration)
|
||||||
|
@ -248,8 +249,8 @@ Press <kbd>?</kbd> in `nnn` to see the list anytime.
|
||||||
t Modification time s Size
|
t Modification time s Size
|
||||||
MISC
|
MISC
|
||||||
!, ^] Spawn SHELL in dir o Launch app
|
!, ^] Spawn SHELL in dir o Launch app
|
||||||
R Run custom script ^S Execute entry
|
^S Run a command R Run custom script
|
||||||
L Lock terminal
|
C Execute entry L Lock terminal
|
||||||
```
|
```
|
||||||
|
|
||||||
Help & settings, file details, media info and archive listing are shown in the PAGER. Please use the PAGER-specific keys in these screens.
|
Help & settings, file details, media info and archive listing are shown in the PAGER. Please use the PAGER-specific keys in these screens.
|
||||||
|
|
6
nnn.1
6
nnn.1
|
@ -147,12 +147,14 @@ MISC
|
||||||
Spawn SHELL in current directory (fallback sh)
|
Spawn SHELL in current directory (fallback sh)
|
||||||
.It Ic o
|
.It Ic o
|
||||||
Launch an application (takes 2 combined arguments)
|
Launch an application (takes 2 combined arguments)
|
||||||
|
.It Ic ^S
|
||||||
|
Run a command
|
||||||
.It Ic R
|
.It Ic R
|
||||||
Run a custom script
|
Run a custom script
|
||||||
.It Ic ^S
|
.It Ic C
|
||||||
Execute entry
|
Execute entry
|
||||||
.It Ic L
|
.It Ic L
|
||||||
Lock terminal (Linux only)
|
Lock terminal
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
Backing up one directory level will set the cursor position at the
|
Backing up one directory level will set the cursor position at the
|
||||||
|
|
72
src/nnn.c
72
src/nnn.c
|
@ -1288,7 +1288,7 @@ end:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Show a prompt with input string and return the changes */
|
/* Show a prompt with input string and return the changes */
|
||||||
static char *xreadline(char *fname, char *prompt)
|
static char *xreadline(char *prefill, char *prompt)
|
||||||
{
|
{
|
||||||
size_t len, pos;
|
size_t len, pos;
|
||||||
int x, y, r;
|
int x, y, r;
|
||||||
|
@ -1298,9 +1298,9 @@ static char *xreadline(char *fname, char *prompt)
|
||||||
cleartimeout();
|
cleartimeout();
|
||||||
printprompt(prompt);
|
printprompt(prompt);
|
||||||
|
|
||||||
if (fname) {
|
if (prefill) {
|
||||||
DPRINTF_S(fname);
|
DPRINTF_S(prefill);
|
||||||
len = pos = mbstowcs(buf, fname, NAME_MAX);
|
len = pos = mbstowcs(buf, prefill, NAME_MAX);
|
||||||
} else
|
} else
|
||||||
len = (size_t)-1;
|
len = (size_t)-1;
|
||||||
|
|
||||||
|
@ -2060,8 +2060,8 @@ static bool show_help(char *path)
|
||||||
"et Modification time s Size\n"
|
"et Modification time s Size\n"
|
||||||
"1MISC\n"
|
"1MISC\n"
|
||||||
"a!, ^] Spawn SHELL in dir o Launch app\n"
|
"a!, ^] Spawn SHELL in dir o Launch app\n"
|
||||||
"eR Run custom script ^S Execute entry\n"
|
"d^S Run a command R Run custom script\n"
|
||||||
"eL Lock terminal\n"};
|
"eC Execute entry L Lock terminal\n"};
|
||||||
|
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -3368,7 +3368,8 @@ nochange:
|
||||||
if (!ndents)
|
if (!ndents)
|
||||||
goto nochange; // fallthrough
|
goto nochange; // fallthrough
|
||||||
case SEL_SHELL: // fallthrough
|
case SEL_SHELL: // fallthrough
|
||||||
case SEL_SCRIPT:
|
case SEL_SCRIPT: // fallthrough
|
||||||
|
case SEL_RUNCMD:
|
||||||
if (sel == SEL_EXEC) {
|
if (sel == SEL_EXEC) {
|
||||||
/* Check if this is a directory */
|
/* Check if this is a directory */
|
||||||
if (S_ISDIR(dents[cur].mode)) {
|
if (S_ISDIR(dents[cur].mode)) {
|
||||||
|
@ -3386,35 +3387,40 @@ nochange:
|
||||||
spawn(newpath, NULL, NULL, path, F_NORMAL | F_SIGINT);
|
spawn(newpath, NULL, NULL, path, F_NORMAL | F_SIGINT);
|
||||||
} else if (sel == SEL_SCRIPT) {
|
} else if (sel == SEL_SCRIPT) {
|
||||||
tmp = getenv("NNN_SCRIPT");
|
tmp = getenv("NNN_SCRIPT");
|
||||||
if (tmp) {
|
if (!tmp) {
|
||||||
if (getenv("NNN_MULTISCRIPT")) {
|
|
||||||
size_t _len = xstrlcpy(newpath, tmp, PATH_MAX);
|
|
||||||
|
|
||||||
tmp = xreadline(NULL, "script suffix: ");
|
|
||||||
if (tmp && tmp[0])
|
|
||||||
xstrlcpy(newpath + _len - 1, tmp, PATH_MAX - _len);
|
|
||||||
tmp = newpath;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lstat(tmp, &sb) == -1) {
|
|
||||||
printwarn();
|
|
||||||
goto nochange;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if it's a directory */
|
|
||||||
if (S_ISDIR(sb.st_mode)) {
|
|
||||||
printmsg("directory");
|
|
||||||
goto nochange;
|
|
||||||
}
|
|
||||||
|
|
||||||
dir = NULL; /* dir used as temp var */
|
|
||||||
if (ndents)
|
|
||||||
dir = dents[cur].name;
|
|
||||||
spawn(shell, tmp, dir, path, F_NORMAL | F_SIGINT);
|
|
||||||
} else {
|
|
||||||
printmsg("set NNN_SCRIPT");
|
printmsg("set NNN_SCRIPT");
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (getenv("NNN_MULTISCRIPT")) {
|
||||||
|
size_t _len = xstrlcpy(newpath, tmp, PATH_MAX);
|
||||||
|
|
||||||
|
tmp = xreadline(NULL, "script suffix: ");
|
||||||
|
if (tmp && tmp[0])
|
||||||
|
xstrlcpy(newpath + _len - 1, tmp, PATH_MAX - _len);
|
||||||
|
tmp = newpath;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lstat(tmp, &sb) == -1) {
|
||||||
|
printwarn();
|
||||||
|
goto nochange;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if it's a directory */
|
||||||
|
if (S_ISDIR(sb.st_mode)) {
|
||||||
|
printmsg("directory");
|
||||||
|
goto nochange;
|
||||||
|
}
|
||||||
|
|
||||||
|
dir = NULL; /* dir used as temp var */
|
||||||
|
if (ndents)
|
||||||
|
dir = dents[cur].name;
|
||||||
|
spawn(shell, tmp, dir, path, F_NORMAL | F_SIGINT);
|
||||||
|
} else if (sel == SEL_RUNCMD) {
|
||||||
|
tmp = xreadline(NULL, "> ");
|
||||||
|
if (!tmp || !tmp[0])
|
||||||
|
goto nochange;
|
||||||
|
spawn(shell, "-c", tmp, path, F_NORMAL | F_SIGINT);
|
||||||
} else
|
} else
|
||||||
spawn(shell, shell_arg, NULL, path, F_NORMAL | F_MARKER);
|
spawn(shell, shell_arg, NULL, path, F_NORMAL | F_MARKER);
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,7 @@ enum action {
|
||||||
SEL_EXEC,
|
SEL_EXEC,
|
||||||
SEL_SHELL,
|
SEL_SHELL,
|
||||||
SEL_SCRIPT,
|
SEL_SCRIPT,
|
||||||
|
SEL_RUNCMD,
|
||||||
SEL_RUNEDIT,
|
SEL_RUNEDIT,
|
||||||
SEL_RUNPAGE,
|
SEL_RUNPAGE,
|
||||||
SEL_LOCK,
|
SEL_LOCK,
|
||||||
|
@ -211,13 +212,15 @@ static struct key bindings[] = {
|
||||||
/* Show help */
|
/* Show help */
|
||||||
{ '?', SEL_HELP },
|
{ '?', SEL_HELP },
|
||||||
/* Execute file */
|
/* Execute file */
|
||||||
{ CONTROL('S'), SEL_EXEC },
|
{ 'C', SEL_EXEC },
|
||||||
/* Run command */
|
/* Run command */
|
||||||
{ '!', SEL_SHELL },
|
{ '!', SEL_SHELL },
|
||||||
{ CONTROL(']'), SEL_SHELL },
|
{ CONTROL(']'), SEL_SHELL },
|
||||||
/* Run a custom script */
|
/* Run a custom script */
|
||||||
{ 'R', SEL_SCRIPT },
|
{ 'R', SEL_SCRIPT },
|
||||||
/* Run command with argument */
|
/* Run a command */
|
||||||
|
{ CONTROL('S'), SEL_RUNCMD },
|
||||||
|
/* Open in EDITOR or PAGER */
|
||||||
{ 'e', SEL_RUNEDIT },
|
{ 'e', SEL_RUNEDIT },
|
||||||
{ 'p', SEL_RUNPAGE },
|
{ 'p', SEL_RUNPAGE },
|
||||||
/* Lock screen */
|
/* Lock screen */
|
||||||
|
|
Loading…
Reference in a new issue