]> Sergey Matveev's repositories - nnn.git/commitdiff
Pass current file name as first argument to custom scripts
authorArun Prakash Jana <engineerarun@gmail.com>
Wed, 4 Jul 2018 14:05:36 +0000 (19:35 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Wed, 4 Jul 2018 14:05:36 +0000 (19:35 +0530)
README.md
nnn.1
nnn.c

index d3c707f97fddc47dbe6d3a0b390b248841a505d5..a9d91fb56b332d969e1c9112b9712cce0c1f0e91 100644 (file)
--- 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 865d0ccf29fe61a50dd80effe16e02ff8ced828d..d7190c947763cae3bfca00634492d758e1e5ce6e 100644 (file)
--- 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 fa4c177b5ed96fef55c195c5b5680c1c3e7b1f0c..da731d1a03f3f7272a352f7e8067752fc7af86c0 100644 (file)
--- 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);