aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2018-07-04 19:35:36 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2018-07-04 19:35:36 +0530
commit042d00839245a3acf3cd0ce934f916a63dac4247 (patch)
treead7b67dad9f13a0df57558816e7089754fded7ae
parent74a0dc0a97e05702b18d4df7547ca7dc59f507c8 (diff)
downloadnnn-042d00839245a3acf3cd0ce934f916a63dac4247.tar.gz
Pass current file name as first argument to custom scripts
-rw-r--r--README.md2
-rw-r--r--nnn.12
-rw-r--r--nnn.c7
3 files changed, 9 insertions, 2 deletions
diff --git a/README.md b/README.md
index d3c707f..a9d91fb 100644
--- a/README.md
+++ b/README.md
@@ -421,6 +421,8 @@ Note that you may want to keep quotes disabled in this case.
#### 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 NNN_SCRIPT=/usr/local/bin/nscript
diff --git a/nnn.1 b/nnn.1
index 865d0cc..d7190c9 100644
--- a/nnn.1
+++ b/nnn.1
@@ -263,7 +263,7 @@ screensaver.
\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.
+\fBNNN_SCRIPT:\fR path to a custom script to invoke with currently selected file name as argument 1.
.Bd -literal
export NNN_SCRIPT=/usr/local/bin/nscript
.Ed
diff --git a/nnn.c b/nnn.c
index fa4c177..da731d1 100644
--- a/nnn.c
+++ b/nnn.c
@@ -3239,7 +3239,12 @@ nochange:
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 {
spawn(run, NULL, NULL, path, F_NORMAL | F_MARKER);