vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 7cd9fef16e3d4ec26cba5e3952aca95d0084d159
parent 3723b78b39693d170f03d346e47ab3c14a91acb5
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sun,  5 Feb 2017 23:15:55 +0100

vis: set $vis_file{name,path} environment variables for external commands

Diffstat:
Mman/vis.1 | 6++++++
Mvis.c | 6++++++
2 files changed, 12 insertions(+), 0 deletions(-)

diff --git 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 @@ -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