rwd, conswdir – maintain remote working directory


rwd path

conswdir [ prog ]


Rwd and conswdir conspire to keep rio(4) and acme(4) informed about the current directory on remote systems during login sessions. Rio and acme include this information in plumb messages sent to plumber(4). If the remote system’s name space is mounted in the plumber’s name space, the end result is that file paths printed during the session are plumbable.

Rwd informs rio and acme of directory changes. The name of the remote machine is taken from the environment variable $remotesys. Rwd writes the full path to /dev/wdir; writes the last element of the path, suffixed by @remotesys, to /dev/label; and when run inside a win (see acme(1)) window, changes the window title to path/-remotesys using /dev/acme/ctl.

Conswdir copies standard input to standard output, looking for in-band messages about directory changes. The messages are of the form:



where \033 and \007 are ASCII escape and bell characters. Such messages are removed from the stream and not printed to standard output; for each such message conswdir runs prog (default /bin/rwd) with path as its only argument.


Add this plumbing rule (see plumb(6)) in order to run commands in the plumber’s name space:


# have plumber run command
kind is text
data matches 'Local (.*)'
plumb to none
plumb start rc -c $1

Mount a Unix system in your name space and the plumber’s:


% 9fs unix
% plumb 'Local 9fs unix'

(If you’re using acme, execute Local 9fs unix with the middle button to mount the Unix system in acme’s name space.)

Connect to the Unix system, processing in-band directory change messages:


% ssh unix | aux/conswdir

Add this shell function to your .profile on the Unix system to generate directory change messages every time a cd command is executed:


H=`hostname | sed 's/\..*//'`
_cd () {
	\cd $* &&
	case $- in
		echo /n/$H$_dir | awk '{printf("\033];%s\007", $1);}'
alias cd=_cd

The examples described so far only help for relative path names. Add this plumbing rule to handle rooted names like /usr/include/stdio.h:


# remote rooted path names
type is text
wdir matches '/n/unix(/.*)?'
data matches '/([.a-zA-Z¡-￿0-9_/\-]*[a-zA-Z¡-￿0-9_/\-])('$addr')?'
arg isfile /n/unix/$1
data set $file
attr add addr=$3
plumb to edit
plumb client window $editor




plumber(4), plumb(6), srv(4)


This mechanism is clunky, but Unix and SSH make it hard to build a better one.

The escape sequence was chosen because it changes the title on xterm windows.