Explorar el Código

Run a custom script support

master
Arun Prakash Jana hace 7 años
padre
commit
8d7a56cbaa
No se encontró ninguna clave conocida en la base de datos para esta firma ID de clave GPG: A75979F35C080412
Se han modificado 6 ficheros con 54 adiciones y 13 borrados
  1. +13
    -2
      README.md
  2. +10
    -0
      nlay
  3. +3
    -2
      nlay.1
  4. +9
    -2
      nnn.1
  5. +15
    -6
      nnn.c
  6. +4
    -1
      nnn.h

+ 13
- 2
README.md Ver fichero

@@ -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)
- [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 @@ Have fun with it! PRs are welcome. Check out [#1](https://github.com/jarun/nnn/i
- 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 @@ optional arguments:
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 @@ The following abbreviations are used in the detail view:
| 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):

@@ -407,6 +410,14 @@ so you can -

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

The default color for directories is blue. Option `-c` accepts color codes from 0 to 7 to use a different color:


+ 10
- 0
nlay Ver fichero

@@ -83,6 +83,16 @@ elif [ "$2" == "screensaver" ]; then
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 ------------------


+ 3
- 2
nlay.1 Ver fichero

@@ -9,7 +9,7 @@
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 @@ 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.
.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


+ 9
- 2
nnn.1 Ver fichero

@@ -82,8 +82,8 @@ Show full media info
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 @@ Toggle disk usage analyzer mode
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 @@ screensaver.
.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


+ 15
- 6
nnn.c Ver fichero

@@ -1930,11 +1930,12 @@ show_help(char *path)
"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 @@ nochange:
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)


+ 4
- 1
nnn.h Ver fichero

@@ -42,6 +42,7 @@ enum action {
SEL_RENAMEALL,
SEL_HELP,
SEL_RUN,
SEL_RUNSCRIPT,
SEL_RUNARG,
SEL_CDQUIT,
SEL_QUIT,
@@ -161,11 +162,13 @@ static struct key bindings[] = {
{ 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" },


||||||
x
 
000:0
Cargando…
Cancelar
Guardar