Hi,
vi(1) currently has support for filename tab expanding, but to expand the
tilde '~' character to $HOME it has to vfork/exec ksh. Yikes.
770 vi CALL execve(0x2cf0b7bce80,0x7f7ffffbf960,0x2cef006cc00)
770 vi NAMI "/bin/ksh"
770 ksh RET execve 0
90346 vi RET vfork 770/0x302
This also conflicts with the -S or 'secure' option which prevents
executing external commands using pledge(2).
"Shell expansions not supported when the secure edit option is set."
It seems to work with my use case, but it would be helpful if other
vi users could take a look!
-Bryan.
Index: ex/ex_argv.c
===================================================================
RCS file: /cvs/src/usr.bin/vi/ex/ex_argv.c,v
retrieving revision 1.20
diff -u -p -u -r1.20 ex_argv.c
--- usr.bin/vi/ex/ex_argv.c 27 May 2016 09:18:12 -0000 1.20
+++ usr.bin/vi/ex/ex_argv.c 22 Aug 2017 18:20:25 -0000
@@ -320,6 +320,21 @@ argv_fexp(SCR *sp, EXCMD *excp, char *cm
p += tlen;
F_SET(excp, E_MODIFY);
break;
+ case '~':
+ if ((t = getenv("HOME")) == NULL || *t == '\0') {
+ msgq(sp, M_ERR,
+ "Unable to substitute HOME directory");
+ return (1);
+ }
+ tlen = strlen(t);
+ len += tlen;
+ off = p - bp;
+ ADD_SPACE_RET(sp, bp, blen, len);
+ p = bp + off;
+ memcpy(p, t, tlen);
+ p += tlen;
+ F_SET(excp, E_MODIFY);
+ break;
case '%':
if ((t = sp->frp->name) == NULL) {
msgq(sp, M_ERR,