Run a custom script support

This commit is contained in:
Arun Prakash Jana 2018-03-19 05:32:16 +05:30
parent 5624905803
commit 8d7a56cbaa
No known key found for this signature in database
GPG key ID: A75979F35C080412
6 changed files with 54 additions and 13 deletions

View file

@ -59,6 +59,7 @@ Have fun with it! PRs are welcome. Check out [#1](https://github.com/jarun/nnn/i
- [cd on quit](#cd-on-quit) - [cd on quit](#cd-on-quit)
- [copy file paths to clipboard](#copy-file-paths-to-clipboard) - [copy file paths to clipboard](#copy-file-paths-to-clipboard)
- [copy file paths when X is missing](#copy-file-paths-when-x-is-missing) - [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) - [change dir color](#change-dir-color)
- [file copy, move, delete](#file-copy-move-delete) - [file copy, move, delete](#file-copy-move-delete)
- [boost chdir prompt](#boost-chdir-prompt) - [boost chdir prompt](#boost-chdir-prompt)
@ -97,6 +98,7 @@ Have fun with it! PRs are welcome. Check out [#1](https://github.com/jarun/nnn/i
- Create, rename files and directories - Create, rename files and directories
- Batch rename/move/delete current directory entries in vidir (from moreutils) - Batch rename/move/delete current directory entries in vidir (from moreutils)
- Spawn SHELL (fallback sh) in the current directory - 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) - Copy absolute file paths with/without X (*easy* shell integration)
- Change directory at exit (*easy* shell integration) - Change directory at exit (*easy* shell integration)
- Open any file in EDITOR (fallback vi) or PAGER (fallback less) - Open any file in EDITOR (fallback vi) or PAGER (fallback less)
@ -224,11 +226,12 @@ optional arguments:
M | Full media info M | Full media info
n | Create new n | Create new
^R | Rename entry ^R | Rename entry
R | Rename dir entries r | Open dir in vidir
s | Toggle sort by size s | Toggle sort by size
S, ^J | Toggle du mode S, ^J | Toggle du mode
t | Toggle sort by mtime t | Toggle sort by mtime
! | Spawn SHELL in dir ! | Spawn SHELL in dir
R | Run custom script
e | Edit entry in EDITOR e | Edit entry in EDITOR
o | Open dir in file manager o | Open dir in file manager
p | Open entry in PAGER p | Open entry in PAGER
@ -290,7 +293,7 @@ The following abbreviations are used in the detail view:
| vlock (Linux) | terminal locker | | vlock (Linux) | terminal locker |
| $EDITOR | edit files (fallback vi) | | $EDITOR | edit files (fallback vi) |
| $PAGER | page through files (fallback less) | | $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): - To edit all text files in EDITOR (preferably CLI, fallback vi):
@ -407,6 +410,14 @@ so you can -
Note that you may want to keep quotes disabled in this case. 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 <kbd>R</kbd> to run the script in the current directory.
#### change dir color #### change dir color
The default color for directories is blue. Option `-c` accepts color codes from 0 to 7 to use a different color: The default color for directories is blue. Option `-c` accepts color codes from 0 to 7 to use a different color:

10
nlay
View file

@ -83,6 +83,16 @@ elif [ "$2" == "screensaver" ]; then
type -P $app &>/dev/null && type -P $app &>/dev/null &&
eval $app $opts $bg eval $app $opts $bg
exit 0 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 fi
#----------------- RUN APP ------------------ #----------------- RUN APP ------------------

5
nlay.1
View file

@ -9,7 +9,7 @@
file/path type/action file/path type/action
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm .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 .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, 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 .Nm
@ -22,12 +22,13 @@ supports the following options:
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. 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 .Pp
"type/action" "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 .Sh USAGE
.Pp .Pp
.Bd -literal .Bd -literal
$ nlay info.txt text $ nlay info.txt text
$ nlay . search $ nlay . search
$ nlay ~/script.sh script
$ nlay "" screensaver $ nlay "" screensaver
.Ed .Ed
.Sh AUTHOR .Sh AUTHOR

11
nnn.1
View file

@ -82,8 +82,8 @@ Show full media info
Create a new file or directory Create a new file or directory
.It Ic ^R .It Ic ^R
Rename selected entry Rename selected entry
.It Ic R .It Ic r
Rename directory entries Open directory in vidir
.It Ic s .It Ic s
Toggle sort by file size Toggle sort by file size
.It Ic S, ^J .It Ic S, ^J
@ -92,6 +92,8 @@ Toggle disk usage analyzer mode
Toggle sort by time modified Toggle sort by time modified
.It Ic \&! .It Ic \&!
Spawn SHELL in PWD (fallback sh) Spawn SHELL in PWD (fallback sh)
.It Ic R
Run a custom script
.It Ic e .It Ic e
Open current entry in EDITOR (fallback vi) Open current entry in EDITOR (fallback vi)
.It Ic o .It Ic o
@ -255,6 +257,11 @@ screensaver.
.Pp .Pp
\fBNNN_QUOTE_ON:\fR wrap copied paths within single quotes. Useful for pasting \fBNNN_QUOTE_ON:\fR wrap copied paths within single quotes. Useful for pasting
names in the shell. 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 .Sh KNOWN ISSUES
If you are using urxvt you might have to set backspacekey to DEC. If you are using urxvt you might have to set backspacekey to DEC.
.Sh AUTHORS .Sh AUTHORS

13
nnn.c
View file

@ -1930,11 +1930,12 @@ show_help(char *path)
"eM | Full media info\n" "eM | Full media info\n"
"en | Create new\n" "en | Create new\n"
"d^R | Rename entry\n" "d^R | Rename entry\n"
"eR | Rename dir entries\n" "er | Open dir in vidir\n"
"es | Toggle sort by size\n" "es | Toggle sort by size\n"
"aS, ^J | Toggle du mode\n" "aS, ^J | Toggle du mode\n"
"et | Toggle sort by mtime\n" "et | Toggle sort by mtime\n"
"e! | Spawn SHELL in dir\n" "e! | Spawn SHELL in dir\n"
"eR | Run custom script\n"
"ee | Edit entry in EDITOR\n" "ee | Edit entry in EDITOR\n"
"eo | Open dir in file manager\n" "eo | Open dir in file manager\n"
"ep | Open entry in PAGER\n" "ep | Open entry in PAGER\n"
@ -3175,13 +3176,21 @@ nochange:
case SEL_HELP: case SEL_HELP:
show_help(path); show_help(path);
break; break;
case SEL_RUN: case SEL_RUN: // fallthorugh
case SEL_RUNSCRIPT:
run = xgetenv(env, run); run = xgetenv(env, run);
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); spawn(run, NULL, NULL, path, F_NORMAL | F_MARKER);
/* Continue in navigate-as-you-type mode, if enabled */ /* Continue in navigate-as-you-type mode, if enabled */
if (cfg.filtermode) if (cfg.filtermode)
presel = FILTER; presel = FILTER;
}
/* Save current */ /* Save current */
if (ndents > 0) if (ndents > 0)

5
nnn.h
View file

@ -42,6 +42,7 @@ enum action {
SEL_RENAMEALL, SEL_RENAMEALL,
SEL_HELP, SEL_HELP,
SEL_RUN, SEL_RUN,
SEL_RUNSCRIPT,
SEL_RUNARG, SEL_RUNARG,
SEL_CDQUIT, SEL_CDQUIT,
SEL_QUIT, SEL_QUIT,
@ -161,11 +162,13 @@ static struct key bindings[] = {
{ CONTROL('R'), SEL_RENAME, "", "" }, { CONTROL('R'), SEL_RENAME, "", "" },
{ KEY_F(2), SEL_RENAME, "", "" }, /* Undocumented */ { KEY_F(2), SEL_RENAME, "", "" }, /* Undocumented */
/* Rename contents of current dir */ /* Rename contents of current dir */
{ 'R', SEL_RENAMEALL, "", "" }, { 'r', SEL_RENAMEALL, "", "" },
/* Show help */ /* Show help */
{ '?', SEL_HELP, "", "" }, { '?', SEL_HELP, "", "" },
/* Run command */ /* Run command */
{ '!', SEL_RUN, "sh", "SHELL" }, { '!', SEL_RUN, "sh", "SHELL" },
/* Run a custom script */
{ 'R', SEL_RUNSCRIPT, "sh", "SHELL" },
/* Run command with argument */ /* Run command with argument */
{ 'e', SEL_RUNARG, "vi", "EDITOR" }, { 'e', SEL_RUNARG, "vi", "EDITOR" },
{ 'p', SEL_RUNARG, "less", "PAGER" }, { 'p', SEL_RUNARG, "less", "PAGER" },