Support only scripts directory

This commit is contained in:
Arun Prakash Jana 2019-04-06 06:54:06 +05:30
parent 650e51d2e7
commit 4997f047cc
No known key found for this signature in database
GPG key ID: A75979F35C080412
3 changed files with 12 additions and 27 deletions

View file

@ -107,7 +107,6 @@ Have as many scripts as you want to extend the power of `nnn`! Pick from the [sc
- Per-context directory color (default: blue) - Per-context directory color (default: blue)
- Spawn a shell in the current directory - Spawn a shell in the current directory
- Launch applications, run a command - Launch applications, run a command
- Run custom scripts in the current directory
- Repository of custom scripts - Repository of custom scripts
- Run current file as executable - Run current file as executable
- Change directory at exit (*easy* shell integration) - Change directory at exit (*easy* shell integration)
@ -264,7 +263,7 @@ Press <kbd>?</kbd> in `nnn` to see the list anytime.
^W Random s Size t Time modified ^W Random s Size t Time modified
MISC MISC
! ^] Spawn SHELL C Execute entry ! ^] Spawn SHELL C Execute entry
R ^V Run/pick script L Lock terminal R ^V Run script L Lock terminal
^P Prompt ^N Note = Launcher ^P Prompt ^N Note = Launcher
``` ```
@ -382,7 +381,7 @@ The following indicators are used in the detail view:
| `NNN_CONTEXT_COLORS='1234'` | specify per context color [default: '4444' (all blue)] | | `NNN_CONTEXT_COLORS='1234'` | specify per context color [default: '4444' (all blue)] |
| `NNN_IDLE_TIMEOUT=300` | idle seconds before locking terminal [default: disabled] | | `NNN_IDLE_TIMEOUT=300` | idle seconds before locking terminal [default: disabled] |
| `NNN_COPIER='copier.sh'` | system clipboard copier script [default: none] | | `NNN_COPIER='copier.sh'` | system clipboard copier script [default: none] |
| `NNN_SCRIPT=/home/user/scripts[/script.sh]` | path to script dir or a single script | | `NNN_SCRIPT_DIR=/home/user/scripts` | absolute path to script dir |
| `NNN_NOTE=/home/user/Dropbox/Public/notes` | path to note file [default: none] | | `NNN_NOTE=/home/user/Dropbox/Public/notes` | path to note file [default: none] |
| `NNN_TMPFILE=/tmp/nnn` | file to write current open dir path to for cd on quit | | `NNN_TMPFILE=/tmp/nnn` | file to write current open dir path to for cd on quit |
| `NNN_USE_EDITOR=1` | Open text files in `$EDITOR` (`$VISUAL`, if defined; fallback vi) | | `NNN_USE_EDITOR=1` | Open text files in `$EDITOR` (`$VISUAL`, if defined; fallback vi) |
@ -404,13 +403,9 @@ To lookup keyboard shortcuts at runtime, press <kbd>?</kbd>.
Copy the scripts of your interest from the [user-scripts](https://github.com/jarun/nnn/tree/master/user-scripts) directory and let `nnn` know the location: Copy the scripts of your interest from the [user-scripts](https://github.com/jarun/nnn/tree/master/user-scripts) directory and let `nnn` know the location:
export NNN_SCRIPT=/absolute/path/to/scripts_dir export NNN_SCRIPT_DIR=/absolute/path/to/scripts_dir
Use the run/pick script shortcut to jump to the script directory and pick a script. Repeating the same shortcut cancels the operation and puts you back in the original directory. Use the run script shortcut to jump to the script directory and pick a script. Repeating the same shortcut cancels the operation and puts you back in the original directory.
In case you need only one script:
export NNN_SCRIPT=/absolute/path/to/script
If you have an interesting script feel free to raise a PR. If you have an interesting script feel free to raise a PR.

6
nnn.1
View file

@ -174,11 +174,9 @@ when dealing with the !, e and p commands respectively. A single combination to
The path is shown in the help and configuration screen. The path is shown in the help and configuration screen.
.Ed .Ed
.Pp .Pp
\fBNNN_SCRIPT:\fR \fIabsolute\fR path to a directory to select a script from or a single script to invoke with currently selected file name as argument 1. \fBNNN_SCRIPT_DIR:\fR \fIabsolute\fR path to script directory. Selected script is invoked with currently selected file name as argument 1.
.Bd -literal .Bd -literal
export NNN_SCRIPT=/home/user/scripts export NNN_SCRIPT_DIR=/absolute/path/to/scripts_dir
OR
export NNN_SCRIPT=/usr/local/bin/nscript.sh
.Ed .Ed
.Pp .Pp
\fBNNN_NOTE:\fR \fIabsolute\fR path to a note file. \fBNNN_NOTE:\fR \fIabsolute\fR path to a note file.

View file

@ -357,7 +357,7 @@ static const char * const messages[] = {
#define NNN_CONTEXT_COLORS 2 #define NNN_CONTEXT_COLORS 2
#define NNN_IDLE_TIMEOUT 3 #define NNN_IDLE_TIMEOUT 3
#define NNN_COPIER 4 #define NNN_COPIER 4
#define NNN_SCRIPT 5 #define NNN_SCRIPT_DIR 5
#define NNN_NOTE 6 #define NNN_NOTE 6
#define NNN_TMPFILE 7 #define NNN_TMPFILE 7
#define NNNLVL 8 /* strings end here */ #define NNNLVL 8 /* strings end here */
@ -377,7 +377,7 @@ static const char * const env_cfg[] = {
"NNN_CONTEXT_COLORS", "NNN_CONTEXT_COLORS",
"NNN_IDLE_TIMEOUT", "NNN_IDLE_TIMEOUT",
"NNN_COPIER", "NNN_COPIER",
"NNN_SCRIPT", "NNN_SCRIPT_DIR",
"NNN_NOTE", "NNN_NOTE",
"NNN_TMPFILE", "NNN_TMPFILE",
"NNNLVL", "NNNLVL",
@ -2425,7 +2425,7 @@ static bool show_help(const char *path)
"b^W Random s Size t Time modified\n" "b^W Random s Size t Time modified\n"
"1MISC\n" "1MISC\n"
"9! ^] Spawn SHELL C Execute entry\n" "9! ^] Spawn SHELL C Execute entry\n"
"9R ^V Run/pick script L Lock terminal\n" "9R ^V Run script L Lock terminal\n"
"b^P Prompt ^N Note = Launcher\n"}; "b^P Prompt ^N Note = Launcher\n"};
if (g_tmpfpath[0]) if (g_tmpfpath[0])
@ -2884,7 +2884,7 @@ static void browse(char *ipath)
struct stat sb; struct stat sb;
char *path, *lastdir, *lastname; char *path, *lastdir, *lastname;
char *dir, *tmp; char *dir, *tmp;
char *scriptpath = getenv(env_cfg[NNN_SCRIPT]); char *scriptpath = getenv(env_cfg[NNN_SCRIPT_DIR]);
atexit(dentfree); atexit(dentfree);
@ -3799,7 +3799,7 @@ nochange:
break; break;
case SEL_SCRIPT: case SEL_SCRIPT:
if (!scriptpath) { if (!scriptpath) {
printwait("set NNN_SCRIPT", &presel); printwait("set NNN_SCRIPT_DIR", &presel);
goto nochange; goto nochange;
} }
@ -3808,18 +3808,10 @@ nochange:
goto nochange; goto nochange;
} }
/* Regular script file */ /* Must be a directory */
if (S_ISREG(sb.st_mode)) {
tmp = ndents ? dents[cur].name : NULL;
spawn(scriptpath, tmp, NULL, path, F_NORMAL);
break;
}
/* Must be a directory or a regular file */
if (!S_ISDIR(sb.st_mode)) if (!S_ISDIR(sb.st_mode))
break; break;
/* Script directory */
cfg.runscript ^= 1; cfg.runscript ^= 1;
if (!cfg.runscript && rundir[0]) { if (!cfg.runscript && rundir[0]) {
/* /*