diff options
| author | 2018-12-08 18:22:06 +0530 | |
|---|---|---|
| committer | 2018-12-08 18:22:06 +0530 | |
| commit | 08cfcfea59a8ee0759d3644b06eca597d95d9277 (patch) | |
| tree | 5458aed1fe83a3392e03bb2ab1fe148fd6c9a8af /src | |
| parent | d52482320ab992317438c1f6493d2f500c75d222 (diff) | |
| download | nnn-08cfcfea59a8ee0759d3644b06eca597d95d9277.tar.gz | |
Support run file as executable
Diffstat (limited to 'src')
| -rw-r--r-- | src/nnn.c | 23 | ||||
| -rw-r--r-- | src/nnn.h | 3 |
2 files changed, 24 insertions, 2 deletions
@@ -2060,7 +2060,8 @@ static bool show_help(char *path) "es Size t Modification time\n" "1MISC\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) return FALSE; @@ -3371,9 +3372,27 @@ nochange: close(fd); xstrlcpy(lastname, tmp, NAME_MAX + 1); goto begin; + case SEL_EXEC: + if (!ndents) + goto nochange; // fallthrough case SEL_SHELL: // fallthrough 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"); if (tmp) { if (getenv("NNN_MULTISCRIPT")) { @@ -80,6 +80,7 @@ enum action { SEL_RENAME, SEL_RENAMEALL, SEL_HELP, + SEL_EXEC, SEL_SHELL, SEL_SCRIPT, SEL_RUNEDIT, @@ -209,6 +210,8 @@ static struct key bindings[] = { { 'r', SEL_RENAMEALL }, /* Show help */ { '?', SEL_HELP }, + /* Execute file */ + { CONTROL('S'), SEL_EXEC }, /* Run command */ { '!', SEL_SHELL }, { CONTROL(']'), SEL_SHELL }, |