Pass current file name as first argument to custom scripts

This commit is contained in:
Arun Prakash Jana 2018-07-04 19:35:36 +05:30
parent 74a0dc0a97
commit 042d008392
No known key found for this signature in database
GPG key ID: A75979F35C080412
3 changed files with 9 additions and 2 deletions

View file

@ -421,6 +421,8 @@ Note that you may want to keep quotes disabled in this case.
#### run custom scripts #### run custom scripts
`nnn` can invoke custom scripts with the currently selected file name as argument 1.
Export the path to the custom executable script: Export the path to the custom executable script:
export NNN_SCRIPT=/usr/local/bin/nscript export NNN_SCRIPT=/usr/local/bin/nscript

2
nnn.1
View file

@ -263,7 +263,7 @@ screensaver.
\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 .Pp
\fBNNN_SCRIPT:\fR path to a custom script to run. \fBNNN_SCRIPT:\fR path to a custom script to invoke with currently selected file name as argument 1.
.Bd -literal .Bd -literal
export NNN_SCRIPT=/usr/local/bin/nscript export NNN_SCRIPT=/usr/local/bin/nscript
.Ed .Ed

7
nnn.c
View file

@ -3239,7 +3239,12 @@ nochange:
tmp = newpath; tmp = newpath;
} }
spawn(run, tmp, NULL, path, F_NORMAL | F_SIGINT);
char *curfile = NULL;
if (ndents > 0)
curfile = dents[cur].name;
spawn(run, tmp, curfile, path, F_NORMAL | F_SIGINT);
} }
} else { } else {
spawn(run, NULL, NULL, path, F_NORMAL | F_MARKER); spawn(run, NULL, NULL, path, F_NORMAL | F_MARKER);