README.md | 15 +++++++++++++-- nlay | 10 ++++++++++ nlay.1 | 5 +++-- nnn.1 | 11 +++++++++-- nnn.c | 21 +++++++++++++++------ nnn.h | 5 ++++- diff --git a/README.md b/README.md index 5e9f3c633f4f7e4b291d9c396022007c1c92ca84..d2e57f484dc1a7ad63526927e1f14af2a431346d 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ - [use cd .....](#use-cd-) - [cd on quit](#cd-on-quit) - [copy file paths to clipboard](#copy-file-paths-to-clipboard) - [copy file paths when X is missing](#copy-file-paths-when-x-is-missing) + - [run a custom script](#run-a-custom-script) - [change dir color](#change-dir-color) - [file copy, move, delete](#file-copy-move-delete) - [boost chdir prompt](#boost-chdir-prompt) @@ -97,6 +98,7 @@ - Convenience - Create, rename files and directories - Batch rename/move/delete current directory entries in vidir (from moreutils) - Spawn SHELL (fallback sh) in the current directory + - Run a custom script in the current directory - Copy absolute file paths with/without X (*easy* shell integration) - Change directory at exit (*easy* shell integration) - Open any file in EDITOR (fallback vi) or PAGER (fallback less) @@ -224,11 +226,12 @@ m | Brief media info M | Full media info n | Create new ^R | Rename entry - R | Rename dir entries + r | Open dir in vidir s | Toggle sort by size S, ^J | Toggle du mode t | Toggle sort by mtime ! | Spawn SHELL in dir + R | Run custom script e | Edit entry in EDITOR o | Open dir in file manager p | Open entry in PAGER @@ -290,7 +293,7 @@ | vidir from moreutils | batch rename, move, delete dir entries | | vlock (Linux) | terminal locker | | $EDITOR | edit files (fallback vi) | | $PAGER | page through files (fallback less) | -| $SHELL | spawn a shell in dir (fallback sh) | +| $SHELL | spawn a shell, run script (fallback sh) | - To edit all text files in EDITOR (preferably CLI, fallback vi): @@ -406,6 +409,14 @@ # fish ls -ltr (ncp) Note that you may want to keep quotes disabled in this case. + +#### run a custom script + +Export the path to the custom script: + + export NNN_SCRIPT=/usr/local/bin/script.sh + +Press R to run the script in the current directory. #### change dir color diff --git a/nlay b/nlay index f68d35cf25d69585ebefd7a5eb74be8026b5bc67..23890b045b2a4daee9433beb1d80348093d4e06a 100755 --- a/nlay +++ b/nlay @@ -83,6 +83,16 @@ type -P $app &>/dev/null && eval $app $opts $bg exit 0 + +#------------------ SCRIPT ------------------ +elif [ "$2" == "script" ]; then + # add commands or a custom script below + + # echo "my commands or custom script" + # sh "path_to_script.sh" + $SHELL "$1" + + exit 0 fi #----------------- RUN APP ------------------ diff --git a/nlay.1 b/nlay.1 index 59dce5b9549d24ab18f2bf3e7ceba0a4846b0013..7e90870ad80aad453b533c248e0f5b9398c4b839 100644 --- a/nlay.1 +++ b/nlay.1 @@ -9,7 +9,7 @@ .Nm file/path type/action .Sh DESCRIPTION .Nm -is shipped with \fInnn\fR to deliver a level of flexibility to users to choose their own apps when running some actions. It has provisions to handle text files too. However, the capability is not used in the latest releases and the file type is limited to text files only. Now +is shipped with \fInnn\fR to deliver a level of flexibility to users to choose their own apps when running some actions, run some commands or custom scripts. It has provisions to handle text files too. However, the capability is not used in the latest releases. Now .Nm is invoked to run a desktop search utility (\fIgnome-search-tool\fR or \fIcatfish\fR in the same order of priority) or screen locker (\fIvlock\fR, Linux-only). However, .Nm @@ -22,12 +22,13 @@ "file/path" The first argument can be the file or path to pass as an argument to the app. It can also be an empty string e.g., while locking the terminal. .Pp "type/action" - This can be any of the strings \fItext\fR, \fIsearch\fR or \fI screensaver\fR. + This can be any of the strings \fItext\fR, \fIsearch\fR, \fIscript\fR or \fI screensaver\fR. .Sh USAGE .Pp .Bd -literal $ nlay info.txt text $ nlay . search +$ nlay ~/script.sh script $ nlay "" screensaver .Ed .Sh AUTHOR diff --git a/nnn.1 b/nnn.1 index 92245a6959e13865a5a390325526e66cc722ac8d..8f78cf4e209a889a2f728acd3676865dd8354d25 100644 --- a/nnn.1 +++ b/nnn.1 @@ -82,8 +82,8 @@ .It Ic n Create a new file or directory .It Ic ^R Rename selected entry -.It Ic R -Rename directory entries +.It Ic r +Open directory in vidir .It Ic s Toggle sort by file size .It Ic S, ^J @@ -92,6 +92,8 @@ .It Ic t Toggle sort by time modified .It Ic \&! Spawn SHELL in PWD (fallback sh) +.It Ic R +Run a custom script .It Ic e Open current entry in EDITOR (fallback vi) .It Ic o @@ -255,6 +257,11 @@ .Ed .Pp \fBNNN_QUOTE_ON:\fR wrap copied paths within single quotes. Useful for pasting names in the shell. +.Pp +\fBNNN_SCRIPT:\fR path to a custom script to run. +.Bd -literal + export NNN_SCRIPT=/usr/local/bin/script.sh +.Ed .Sh KNOWN ISSUES If you are using urxvt you might have to set backspacekey to DEC. .Sh AUTHORS diff --git a/nnn.c b/nnn.c index 588d582e8287391046f5b20736b58ebc3285ecb8..bcba125199dc21939ee4f8305e10ad38801a0eee 100644 --- a/nnn.c +++ b/nnn.c @@ -1930,11 +1930,12 @@ "em | Brief media info\n" "eM | Full media info\n" "en | Create new\n" "d^R | Rename entry\n" - "eR | Rename dir entries\n" + "er | Open dir in vidir\n" "es | Toggle sort by size\n" "aS, ^J | Toggle du mode\n" "et | Toggle sort by mtime\n" "e! | Spawn SHELL in dir\n" + "eR | Run custom script\n" "ee | Edit entry in EDITOR\n" "eo | Open dir in file manager\n" "ep | Open entry in PAGER\n" @@ -3175,13 +3176,21 @@ goto begin; case SEL_HELP: show_help(path); break; - case SEL_RUN: + case SEL_RUN: // fallthorugh + case SEL_RUNSCRIPT: run = xgetenv(env, run); - spawn(run, NULL, NULL, path, F_NORMAL | F_MARKER); - /* Continue in navigate-as-you-type mode, if enabled */ - if (cfg.filtermode) - presel = FILTER; + if (sel == SEL_RUNSCRIPT) { + tmp = getenv("NNN_SCRIPT"); + if (tmp) + spawn(run, tmp, NULL, path, F_NORMAL | F_SIGINT); + } else { + spawn(run, NULL, NULL, path, F_NORMAL | F_MARKER); + + /* Continue in navigate-as-you-type mode, if enabled */ + if (cfg.filtermode) + presel = FILTER; + } /* Save current */ if (ndents > 0) diff --git a/nnn.h b/nnn.h index 9e37f0f4a0944751c20e7ee09e89179a4aa1b752..1b202393c94c3fdd3ff760a81277ba25e0ae1f9c 100644 --- a/nnn.h +++ b/nnn.h @@ -42,6 +42,7 @@ SEL_RENAME, SEL_RENAMEALL, SEL_HELP, SEL_RUN, + SEL_RUNSCRIPT, SEL_RUNARG, SEL_CDQUIT, SEL_QUIT, @@ -161,11 +162,13 @@ /* Show rename prompt */ { CONTROL('R'), SEL_RENAME, "", "" }, { KEY_F(2), SEL_RENAME, "", "" }, /* Undocumented */ /* Rename contents of current dir */ - { 'R', SEL_RENAMEALL, "", "" }, + { 'r', SEL_RENAMEALL, "", "" }, /* Show help */ { '?', SEL_HELP, "", "" }, /* Run command */ { '!', SEL_RUN, "sh", "SHELL" }, + /* Run a custom script */ + { 'R', SEL_RUNSCRIPT, "sh", "SHELL" }, /* Run command with argument */ { 'e', SEL_RUNARG, "vi", "EDITOR" }, { 'p', SEL_RUNARG, "less", "PAGER" },