From: op Date: Tue, 4 Jun 2024 06:48:34 +0000 (+0000) Subject: add dired-up-directory bound to ^ to go up on directory in dired buffers X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=eff72e70060c44fe642057127cc7776a3b957e0a;p=openbsd add dired-up-directory bound to ^ to go up on directory in dired buffers diff from Dante Catalfamo (date [at] lambda [dot] cx) with some minor style nits and the manpage bits from me. ok florian@ --- diff --git a/usr.bin/mg/dired.c b/usr.bin/mg/dired.c index 5cb747c3746..128ed0a31e0 100644 --- a/usr.bin/mg/dired.c +++ b/usr.bin/mg/dired.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dired.c,v 1.102 2023/03/08 04:43:11 guenther Exp $ */ +/* $OpenBSD: dired.c,v 1.103 2024/06/04 06:48:34 op Exp $ */ /* This file is in the public domain. */ @@ -34,6 +34,7 @@ static int d_otherwindow(int, int); static int d_undel(int, int); static int d_undelbak(int, int); static int d_findfile(int, int); +static int d_updirectory(int, int); static int d_ffotherwindow(int, int); static int d_expunge(int, int); static int d_copy(int, int); @@ -122,6 +123,10 @@ static PF diredcz[] = { d_create_directory /* + */ }; +static PF diredcaret[] = { + d_updirectory /* ^ */ +}; + static PF direda[] = { d_filevisitalt, /* a */ rescan, /* b */ @@ -172,9 +177,9 @@ static struct KEYMAPE (1) d_backpagemap = { } }; -static struct KEYMAPE (7) diredmap = { - 7, - 7, +static struct KEYMAPE (8) diredmap = { + 8, + 8, rescan, { { @@ -190,6 +195,9 @@ static struct KEYMAPE (7) diredmap = { { CCHR('Z'), '+', diredcz, (KEYMAP *) & metamap }, + { + '^', '^', diredcaret, NULL + }, { 'a', 'j', direda, NULL }, @@ -224,6 +232,7 @@ dired_init(void) funmap_add(d_undel, "dired-unmark", 0); funmap_add(d_undelbak, "dired-unmark-backward", 0); funmap_add(d_killbuffer_cmd, "quit-window", 0); + funmap_add(d_updirectory, "dired-up-directory", 0); maps_add((KEYMAP *)&diredmap, "dired"); dobindkey(fundamental_map, "dired", "^Xd"); } @@ -363,6 +372,28 @@ d_findfile(int f, int n) return (readin(fname)); } +int +d_updirectory(int f, int n) +{ + struct buffer *bp; + int ret; + char fname[NFILEN]; + + ret = snprintf(fname, sizeof(fname), "%s..", curbp->b_fname); + if (ret < 0 || (size_t)ret >= sizeof(fname)) + return (ABORT); /* Name is too long. */ + + bp = dired_(fname); + if (bp == NULL) + return (FALSE); + curbp = bp; + if (showbuffer(bp, curwp, WFFULL) != TRUE) + return (FALSE); + if (bp->b_fname[0] != 0) + return (TRUE); + return (readin(fname)); +} + int d_ffotherwindow(int f, int n) { diff --git a/usr.bin/mg/mg.1 b/usr.bin/mg/mg.1 index 4faeb8fb293..ca684157d14 100644 --- a/usr.bin/mg/mg.1 +++ b/usr.bin/mg/mg.1 @@ -1,7 +1,7 @@ -.\" $OpenBSD: mg.1,v 1.136 2023/10/16 08:33:16 op Exp $ +.\" $OpenBSD: mg.1,v 1.137 2024/06/04 06:48:34 op Exp $ .\" This file is in the public domain. .\" -.Dd $Mdocdate: October 16 2023 $ +.Dd $Mdocdate: June 4 2024 $ .Dt MG 1 .Os .Sh NAME @@ -1055,6 +1055,8 @@ dired-next-line dired-shell-command .It + dired-create-directory +.It ^ +dired-up-directory .It a dired-find-alternate-file .It c @@ -1130,6 +1132,8 @@ Remove the deletion flag for the file on the current line. .It Ic dired-unmark-backward Remove the deletion flag from the file listed on the previous line of the dired buffer, then move up to that line. +.It Ic dired-up-directory +Open a dired buffer in the parent directory. .It Ic quit-window Close the current dired buffer. .El