Support run file as executable

This commit is contained in:
Arun Prakash Jana 2018-12-08 18:22:06 +05:30
parent d52482320a
commit 08cfcfea59
No known key found for this signature in database
GPG key ID: A75979F35C080412
4 changed files with 29 additions and 3 deletions

View file

@ -117,6 +117,7 @@ We need contributors. Please visit the ToDo list.
- 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 custom scripts in the current directory - Run custom scripts in the current directory
- Run current file as executable
- 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
- Application launcher - Application launcher
@ -247,7 +248,8 @@ Press <kbd>?</kbd> in `nnn` to see the list anytime.
s Size t Modification time s Size t Modification time
MISC MISC
!, ^] Spawn SHELL in dir o Launch app !, ^] Spawn SHELL in dir o Launch app
R Run custom script L Lock terminal R Run custom script ^S 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.

2
nnn.1
View file

@ -149,6 +149,8 @@ Spawn SHELL in current directory (fallback sh)
Launch an application (takes 2 combined arguments) Launch an application (takes 2 combined arguments)
.It Ic R .It Ic R
Run a custom script Run a custom script
.It Ic ^S
Execute entry
.It Ic L .It Ic L
Lock terminal (Linux only) Lock terminal (Linux only)
.El .El

View file

@ -2060,7 +2060,8 @@ static bool show_help(char *path)
"es Size t Modification time\n" "es Size t Modification time\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 L Lock terminal\n"}; "eR Run custom script ^S Execute entry\n"
"eL Lock terminal\n"};
if (fd == -1) if (fd == -1)
return FALSE; return FALSE;
@ -3371,9 +3372,27 @@ nochange:
close(fd); close(fd);
xstrlcpy(lastname, tmp, NAME_MAX + 1); xstrlcpy(lastname, tmp, NAME_MAX + 1);
goto begin; goto begin;
case SEL_EXEC:
if (!ndents)
goto nochange; // fallthrough
case SEL_SHELL: // fallthrough case SEL_SHELL: // fallthrough
case SEL_SCRIPT: case SEL_SCRIPT:
if (sel == SEL_SCRIPT) { if (sel == SEL_EXEC) {
/* Check if this is a directory */
if (S_ISDIR(dents[cur].mode)) {
printmsg("directory");
goto nochange;
}
/* Check if file is executable */
if (!(dents[cur].mode & 0100)) {
printmsg("Permission denied");
goto nochange;
}
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"); tmp = getenv("NNN_SCRIPT");
if (tmp) { if (tmp) {
if (getenv("NNN_MULTISCRIPT")) { if (getenv("NNN_MULTISCRIPT")) {

View file

@ -80,6 +80,7 @@ enum action {
SEL_RENAME, SEL_RENAME,
SEL_RENAMEALL, SEL_RENAMEALL,
SEL_HELP, SEL_HELP,
SEL_EXEC,
SEL_SHELL, SEL_SHELL,
SEL_SCRIPT, SEL_SCRIPT,
SEL_RUNEDIT, SEL_RUNEDIT,
@ -209,6 +210,8 @@ static struct key bindings[] = {
{ 'r', SEL_RENAMEALL }, { 'r', SEL_RENAMEALL },
/* Show help */ /* Show help */
{ '?', SEL_HELP }, { '?', SEL_HELP },
/* Execute file */
{ CONTROL('S'), SEL_EXEC },
/* Run command */ /* Run command */
{ '!', SEL_SHELL }, { '!', SEL_SHELL },
{ CONTROL(']'), SEL_SHELL }, { CONTROL(']'), SEL_SHELL },