README.md | 4 +++- nnn.1 | 2 ++ src/nnn.c | 23 +++++++++++++++++++++-- src/nnn.h | 3 +++ diff --git a/README.md b/README.md index 4ec87619160d1aad86bcc2c46c71fb97d8e43f9e..be68cd710097ab8417a8c4d38814e354397129ed 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,7 @@ - Batch rename/move/delete (needs vidir) - Show directories in custom color (default: blue) - Spawn a subshell in the current directory - Run custom scripts in the current directory + - Run current file as executable - Change directory at exit (*easy* shell integration) - Edit file in EDITOR or open in PAGER - Application launcher @@ -247,7 +248,8 @@ ^J Disk usage S Apparent du s Size t Modification time MISC !, ^] 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. diff --git a/nnn.1 b/nnn.1 index 9dc6334008fda03157a681f863b570b2c5427477..1bcf3a1f7b84b673b0190d0016280ac68e25533e 100644 --- a/nnn.1 +++ b/nnn.1 @@ -149,6 +149,8 @@ .It Ic o Launch an application (takes 2 combined arguments) .It Ic R Run a custom script +.It Ic ^S +Execute entry .It Ic L Lock terminal (Linux only) .El diff --git a/src/nnn.c b/src/nnn.c index 84df28b08212ef6d3b61f3f1d0298641b77a13c6..4b51ec7bf80412964c628f519495b7066fa473ec 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -2060,7 +2060,8 @@ "d^J Disk usage S Apparent du\n" "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 @@ 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")) { diff --git a/src/nnn.h b/src/nnn.h index 088f5a602e3e8ff0756160ff17cdab27029a6cf1..9e7d5f7d00ecf7f4421d04696e3596f63e16910b 100644 --- a/src/nnn.h +++ b/src/nnn.h @@ -80,6 +80,7 @@ SEL_NEW, SEL_RENAME, SEL_RENAMEALL, SEL_HELP, + SEL_EXEC, SEL_SHELL, SEL_SCRIPT, SEL_RUNEDIT, @@ -209,6 +210,8 @@ /* Rename contents of current dir */ { 'r', SEL_RENAMEALL }, /* Show help */ { '?', SEL_HELP }, + /* Execute file */ + { CONTROL('S'), SEL_EXEC }, /* Run command */ { '!', SEL_SHELL }, { CONTROL(']'), SEL_SHELL },