diff options
author | Kjell Wooding <kjell@cvs.openbsd.org> | 2010-06-26 16:18:45 +0000 |
---|---|---|
committer | Kjell Wooding <kjell@cvs.openbsd.org> | 2010-06-26 16:18:45 +0000 |
commit | 655a24356fe84ac3e110431aaaa1f8ba3deb6cf4 (patch) | |
tree | 56146cc118e8e2e970c7e68d170bee3bbcc9c326 /usr.bin/mg | |
parent | 3d11d69fe7cd386923ba3ef27c5f69e938111ff6 (diff) |
From the Loganaden Velvindron:
Make dired more sane (and emacslike):
* Position cursor at first filename after ..
* Don't reposition cursor on reopening
* Check for permission before attempting to open directory
I took forever to get this in. Thanks, Logan for being patient!
Diffstat (limited to 'usr.bin/mg')
-rw-r--r-- | usr.bin/mg/dired.c | 24 | ||||
-rw-r--r-- | usr.bin/mg/file.c | 12 |
2 files changed, 29 insertions, 7 deletions
diff --git a/usr.bin/mg/dired.c b/usr.bin/mg/dired.c index b5eeaff1081..eb5357dcd65 100644 --- a/usr.bin/mg/dired.c +++ b/usr.bin/mg/dired.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dired.c,v 1.45 2009/06/04 23:39:37 kjell Exp $ */ +/* $OpenBSD: dired.c,v 1.46 2010/06/26 16:18:43 kjell Exp $ */ /* This file is in the public domain. */ @@ -592,8 +592,15 @@ dired_(char *dname) struct buffer *bp; FILE *dirpipe; char line[256]; - int len, ret; + int len, ret, counter, warp; + counter = 0; + warp = 0; + if ((fopen(dname,"r")) == NULL) { + if (errno == EACCES) + ewprintf("Permission denied"); + return (NULL); + } if ((dname = adjustname(dname, FALSE)) == NULL) { ewprintf("Bad directory name"); return (NULL); @@ -624,13 +631,26 @@ dired_(char *dname) while (fgets(&line[2], sizeof(line) - 2, dirpipe) != NULL) { line[strcspn(line, "\n")] = '\0'; /* remove ^J */ (void) addline(bp, line); + if ((strrchr(line,' ')) != NULL) { + counter++; + if ((strcmp((strrchr(line,' '))," ..")) == 0) + warp = counter; + } } + if ((strrchr(line,' ')) != NULL) { + if (strcmp((strrchr(line,' '))," ..") == 0) + warp = counter - 1; + } + if ((strrchr(line,' ')) != NULL) + bp->b_doto = strrchr(line,' ') - line + 1; if (pclose(dirpipe) == -1) { ewprintf("Problem closing pipe to ls : %s", strerror(errno)); return (NULL); } bp->b_dotp = bfirstlp(bp); + while (warp--) + bp->b_dotp = lforw(bp->b_dotp); (void)strlcpy(bp->b_fname, dname, sizeof(bp->b_fname)); (void)strlcpy(bp->b_cwd, dname, sizeof(bp->b_cwd)); if ((bp->b_modes[1] = name_mode("dired")) == NULL) { diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c index ee345924c75..be98250def5 100644 --- a/usr.bin/mg/file.c +++ b/usr.bin/mg/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.71 2009/06/04 23:39:37 kjell Exp $ */ +/* $OpenBSD: file.c,v 1.72 2010/06/26 16:18:44 kjell Exp $ */ /* This file is in the public domain. */ @@ -220,10 +220,12 @@ readin(char *fname) for (wp = wheadp; wp != NULL; wp = wp->w_wndp) { if (wp->w_bufp == curbp) { - wp->w_dotp = wp->w_linep = bfirstlp(curbp); - wp->w_doto = 0; - wp->w_markp = NULL; - wp->w_marko = 0; + if ((fisdir(fname)) != TRUE) { + wp->w_dotp = wp->w_linep = bfirstlp(curbp); + wp->w_doto = 0; + wp->w_markp = NULL; + wp->w_marko = 0; + } } } |