ref: 6ba0b1542f1719f6dd3af1e3a568d4c7c94595a8
parent: a50ea54acc46b5ee57b463ef3e881515cc962c00
author: phil9 <telephil9@gmail.com>
date: Thu Jul 13 17:09:56 EDT 2023
listen on 'vdir' plumber port (thanks sigrid) this allows to change the current patch when a directory is plumbed outside of vdir.
--- 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
@@ -38,7 +39,7 @@
const char ellipsis[] = "…";
char *home;
-char path[256];
+char path[4096];
Dir* dirs;
long ndirs;
Mousectl *mctl;
@@ -162,10 +163,10 @@
void
cd(char *dir)
{
- char newpath[256] = {0};
+ char newpath[4096] = {0};
if(dir == nil)
- snprint(newpath, sizeof path, home);
+ snprint(newpath, sizeof newpath, home);
else if(dir[0] == '/')
snprint(newpath, sizeof newpath, dir);
else
@@ -603,7 +604,7 @@
{
int n, dy;
Dir d;
- char buf[256] = {0};
+ char buf[4096] = {0};
if(oldbuttons == 0 && m.buttons != 0 && ptinrect(m.xy, scrollr))
scrolling = 1;
@@ -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;
}
}