aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-02-05 23:15:55 +0100
committerMarc André Tanner <mat@brain-dump.org>2017-02-05 23:15:55 +0100
commit2464589156b1c75a883b6320328c3479a95dc6ae (patch)
treeee5ce99a212d710018f16f9804198966c06bde68
parent6deb6e077fa85a83d5bd4f54f1f416508c77c126 (diff)
downloadvis-2464589156b1c75a883b6320328c3479a95dc6ae.tar.gz
vis-2464589156b1c75a883b6320328c3479a95dc6ae.tar.xz
vis: set $vis_file{name,path} environment variables for external commands
-rw-r--r--man/vis.16
-rw-r--r--vis.c6
2 files changed, 12 insertions, 0 deletions
diff --git a/man/vis.1 b/man/vis.1
index 6ac8474..6054317 100644
--- a/man/vis.1
+++ b/man/vis.1
@@ -520,6 +520,12 @@ or
if the shell command is omitted, the last shell command
.Pq "of any type"
is substituted.
+Unless the file being edited is unnamed, all these external commands
+can refer to its absolute path and file name through the
+.Ic $vis_filepath
+and
+.Ic $vis_filename
+environment variables.
.Ss Loops and conditionals
.Bl -tag -width indent
.It Ic x/regexp/ Bq command
diff --git a/vis.c b/vis.c
index 8a26415..0f596ee 100644
--- a/vis.c
+++ b/vis.c
@@ -1548,6 +1548,12 @@ int vis_pipe(Vis *vis, File *file, Filerange *range, const char *argv[],
close(perr[1]);
close(null);
+ if (file->name) {
+ char *name = strrchr(file->name, '/');
+ setenv("vis_filepath", file->name, 1);
+ setenv("vis_filename", name ? name+1 : file->name, 1);
+ }
+
if (!argv[1])
execlp(vis->shell, vis->shell, "-c", argv[0], (char*)NULL);
else