summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcloder <cloder@openbsd.org>2005-05-27 08:52:30 +0000
committercloder <cloder@openbsd.org>2005-05-27 08:52:30 +0000
commitfebbdc09b0f15e489797b7a1a4bcdbca24bafc6f (patch)
treec6abc7b9d7c876efa37ef557455515e961a22eb5
parentWhen the neighbor at the other end of the virtual link goes to state (diff)
downloadwireguard-openbsd-febbdc09b0f15e489797b7a1a4bcdbca24bafc6f.tar.xz
wireguard-openbsd-febbdc09b0f15e489797b7a1a4bcdbca24bafc6f.zip
In find file, behave like emacs: the default starting directory for
completion is the directory of the current buffer's file, if any, rather than the working directory from where you launched mg. Prodding by reyk, ok reyk and fgont
-rw-r--r--usr.bin/mg/file.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c
index 69dfd6d7159..a901f6e8d86 100644
--- a/usr.bin/mg/file.c
+++ b/usr.bin/mg/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.33 2005/04/21 19:16:21 beck Exp $ */
+/* $OpenBSD: file.c,v 1.34 2005/05/27 08:52:30 cloder Exp $ */
/*
* File commands.
@@ -39,9 +39,18 @@ int
filevisit(int f, int n)
{
BUFFER *bp;
- char fname[NFILEN], *bufp, *adjf;
+ char fname[NFILEN], *bufp, *adjf, *slash;
+
+ if (curbp->b_fname && curbp->b_fname[0] != '\0') {
+ strlcpy(fname, curbp->b_fname, sizeof(fname));
+ if ((slash = strrchr(fname, '/')) != NULL) {
+ *(slash + 1) = '\0';
+ }
+ }
+ else
+ fname[0] = '\0';
- bufp = eread("Find file: ", fname, NFILEN, EFNEW | EFCR | EFFILE);
+ bufp = eread("Find file: ", fname, NFILEN, EFNEW | EFCR | EFFILE | EFDEF);
if (bufp == NULL)
return (ABORT);
else if (bufp[0] == '\0')