diff a50ea54acc46b5ee57b463ef3e881515cc962c00 uncommitted --- a/./README.md +++ b/./README.md @@ -1,6 +1,6 @@ vdir ===== -A minimalistic visual directory browser for Plan9. +A minimalistic visual directory browser for Plan 9. ![vdir](vdir.png) @@ -31,13 +31,25 @@ Path plumbing: -------------- -When right-clicking the path in the toolbar, the path name is sent to plumber. -This can be used to open a window in the directory for instance: +When right-clicking the path in the toolbar, or pressing Space, the +path name is sent to plumber. This can be used to open a window in +the directory for instance: + ``` src is vdir type is text arg isdir $data plumb start window -cd $data rc +``` + +In addition, a plumb rule can be installed so that plumbing a +directory will change the current path of a running vdir: + +``` +type is text +arg isdir $data +plumb to vdir +plumb client window vdir ``` Disclaimer: --- a/./vdir.c +++ b/./vdir.c @@ -25,6 +25,7 @@ Emouse, Eresize, Ekeyboard, + Eplumb, }; enum @@ -162,7 +163,7 @@ void cd(char *dir) { - char newpath[256] = {0}; + char newpath[4096] = {0}; if(dir == nil) snprint(newpath, sizeof path, home); @@ -711,6 +712,29 @@ } void +plumbdir(void *c) +{ + Plumbmsg *m; + char *s; + int f; + + if((f = plumbopen("vdir", OREAD)) >= 0){ + while((m = plumbrecv(f)) != nil){ + s = m->data; + if(*s != '/' && m->wdir != nil) + s = smprint("%s/%.*s", m->wdir, m->ndata, m->data); + else + s = smprint("%.*s", m->ndata, m->data); + plumbfree(m); + if(sendp(c, s) != 1) + break; + } + } + + threadexits(nil); +} + +void usage(void) { fprint(2, "usage: %s [-r] [path]\n", argv0); @@ -722,10 +746,12 @@ { Mouse m; Rune k; + char *d; Alt alts[] = { { nil, &m, CHANRCV }, { nil, nil, CHANRCV }, { nil, &k, CHANRCV }, + { nil, &d, CHANRCV }, { nil, nil, CHANEND }, }; @@ -760,6 +786,8 @@ alts[Emouse].c = mctl->c; alts[Eresize].c = mctl->resizec; alts[Ekeyboard].c = kctl->c; + alts[Eplumb].c = chancreate(sizeof(d), 1); + proccreate(plumbdir, alts[Eplumb].c, 4096); readhome(); loaddirs(); initcolors(); @@ -775,6 +803,11 @@ break; case Ekeyboard: evtkey(k); + break; + case Eplumb: + cd(d); + free(d); + redraw(); break; } }