README.md | 5 +++-- nnn.1 | 6 ++++-- src/nnn.c | 66 +++++++++++++++++++++++++++++------------------------ src/nnn.h | 7 +++++-- diff --git a/README.md b/README.md index b4d77527e39a2645ad5287147088adcb9c64409e..1120649789f256ab51ba02f6f1f32fa1194f2d79 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,7 @@ - Transfer files using lftp - Batch rename/move/delete (needs vidir) - Show directories in custom color (default: blue) - Spawn a subshell in the current directory + - Run a command - Run custom scripts in the current directory - Run current file as executable - Change directory at exit (*easy* shell integration) @@ -248,8 +249,8 @@ ^J Disk usage S Apparent du t Modification time s Size MISC !, ^] Spawn SHELL in dir o Launch app - R Run custom script ^S Execute entry - L Lock terminal + ^S Run a command R Run custom script + 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. diff --git a/nnn.1 b/nnn.1 index 62b1067a60133ffe7ce900863d49f82477f60b87..b411f67cafb540829936cb50c7656474d976ca48 100644 --- a/nnn.1 +++ b/nnn.1 @@ -147,12 +147,14 @@ .It Ic \&!, ^] Spawn SHELL in current directory (fallback sh) .It Ic o Launch an application (takes 2 combined arguments) +.It Ic ^S +Run a command .It Ic R Run a custom script -.It Ic ^S +.It Ic C Execute entry .It Ic L -Lock terminal (Linux only) +Lock terminal .El .Pp Backing up one directory level will set the cursor position at the diff --git a/src/nnn.c b/src/nnn.c index 88fc0c66f0f1005ee10cc020be28cb4c146dada2..f79a1bd41c19fa291722c03db4d0faf78aff753b 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -1288,7 +1288,7 @@ return *ch; } /* 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; int x, y, r; @@ -1298,9 +1298,9 @@ cleartimeout(); printprompt(prompt); - if (fname) { - DPRINTF_S(fname); - len = pos = mbstowcs(buf, fname, NAME_MAX); + if (prefill) { + DPRINTF_S(prefill); + len = pos = mbstowcs(buf, prefill, NAME_MAX); } else len = (size_t)-1; @@ -2060,8 +2060,8 @@ "d^J Disk usage S Apparent du\n" "et Modification time s Size\n" "1MISC\n" "a!, ^] Spawn SHELL in dir o Launch app\n" - "eR Run custom script ^S Execute entry\n" - "eL Lock terminal\n"}; + "d^S Run a command R Run custom script\n" + "eC Execute entry L Lock terminal\n"}; if (fd == -1) return FALSE; @@ -3368,7 +3368,8 @@ case SEL_EXEC: if (!ndents) goto nochange; // fallthrough case SEL_SHELL: // fallthrough - case SEL_SCRIPT: + case SEL_SCRIPT: // fallthrough + case SEL_RUNCMD: if (sel == SEL_EXEC) { /* Check if this is a directory */ if (S_ISDIR(dents[cur].mode)) { @@ -3386,35 +3387,40 @@ mkpath(path, dents[cur].name, newpath, PATH_MAX); spawn(newpath, NULL, NULL, path, F_NORMAL | F_SIGINT); } else if (sel == SEL_SCRIPT) { tmp = getenv("NNN_SCRIPT"); - if (tmp) { - if (getenv("NNN_MULTISCRIPT")) { - size_t _len = xstrlcpy(newpath, tmp, PATH_MAX); + if (!tmp) { + printmsg("set NNN_SCRIPT"); + goto nochange; + } - tmp = xreadline(NULL, "script suffix: "); - if (tmp && tmp[0]) - xstrlcpy(newpath + _len - 1, tmp, PATH_MAX - _len); - tmp = newpath; - } + if (getenv("NNN_MULTISCRIPT")) { + size_t _len = xstrlcpy(newpath, tmp, PATH_MAX); - if (lstat(tmp, &sb) == -1) { - printwarn(); - goto nochange; - } + tmp = xreadline(NULL, "script suffix: "); + if (tmp && tmp[0]) + xstrlcpy(newpath + _len - 1, tmp, PATH_MAX - _len); + tmp = newpath; + } - /* Check if it's a directory */ - if (S_ISDIR(sb.st_mode)) { - printmsg("directory"); - goto nochange; - } + if (lstat(tmp, &sb) == -1) { + printwarn(); + 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"); + /* 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 spawn(shell, shell_arg, NULL, path, F_NORMAL | F_MARKER); diff --git a/src/nnn.h b/src/nnn.h index 9e7d5f7d00ecf7f4421d04696e3596f63e16910b..74cc815c7ccc9d8d5e7d20fa4d69d8ce0ad5c859 100644 --- a/src/nnn.h +++ b/src/nnn.h @@ -83,6 +83,7 @@ SEL_HELP, SEL_EXEC, SEL_SHELL, SEL_SCRIPT, + SEL_RUNCMD, SEL_RUNEDIT, SEL_RUNPAGE, SEL_LOCK, @@ -211,13 +212,15 @@ { 'r', SEL_RENAMEALL }, /* Show help */ { '?', SEL_HELP }, /* Execute file */ - { CONTROL('S'), SEL_EXEC }, + { 'C', SEL_EXEC }, /* Run command */ { '!', SEL_SHELL }, { CONTROL(']'), SEL_SHELL }, /* Run a custom script */ { 'R', SEL_SCRIPT }, - /* Run command with argument */ + /* Run a command */ + { CONTROL('S'), SEL_RUNCMD }, + /* Open in EDITOR or PAGER */ { 'e', SEL_RUNEDIT }, { 'p', SEL_RUNPAGE }, /* Lock screen */