RWD(1)                                                     RWD(1)

     NAME
          rwd, conswdir - maintain remote working directory

     SYNOPSIS
          rwd path

          conswdir [ prog ]

     DESCRIPTION
          Rwd and conswdir conspire to keep rio(4) and acme(4)
          informed about the current directory on remote systems dur-
          ing 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:

               \033];path\007

          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.

     EXAMPLES
          Add this plumbing rule (see plumb(6)) in order to run com-
          mands 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'

     Page 1                       Plan 9            (printed 12/21/24)

     RWD(1)                                                     RWD(1)

          (If you're using acme, execute Local 9fs unix with the mid-
          dle 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 com-
          mand is executed:

               H=`hostname | sed 's/\..*//'`
               _cd () {
                    \cd $* &&
                    case $- in
                    *i*)
                         _dir=`pwd`
                         echo /n/$H$_dir | awk '{printf("\033];%s\007", $1);}'
                    esac
               }
               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

     SOURCE
          /rc/bin/rwd
          /sys/src/cmd/aux/conswdir.c

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

     BUGS
          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.

     Page 2                       Plan 9            (printed 12/21/24)