WorkingDirectoryDoc.tioga
Peter Kessler, February 12, 1986 3:23:27 pm PST
WorkingDirectory
CEDAR 6.0 — FOR INTERNAL XEROX USE ONLY
WorkingDirectory
Peter Kessler
© Copyright 1986 Xerox Corporation. All rights reserved.
Abstract: This program manipulates the same data structures as the CommandTool that define the current working directory and stack of working directories of a command tool. The printing of the current working directory (e.g. in the label of an iconic CommandTool) has been shortened, and the directory stack can now be printed out and rolled.
Created by: Peter Kessler
Maintained by: Peter Kessler <PeterKessler>
Keywords: CommandTool, working directory, directory stack, icon labels
XEROX  Xerox Corporation
   Palo Alto Research Center
   3333 Coyote Hill Road
   Palo Alto, California 94304

For Internal Xerox Use Only
1. The Current Working Directory and the Stack of Working Directories
Working Directories
The CommandTool maintains what it thinks of as the current working directory (possibly different from the FS default working directory?). The current working directory can be changed with (among others) the ``cd'' command. The current working directory is prominently displayed in the CommandTool herald. When the CommandTool is made iconic, the verbose prefix to the current working directory pushes the interesting part of the directory name out of the icon. Sigh. (The starting point of this program was to replace that verbose prefix with something that could be displayed in a CommandTool's icon label. Probably, the right thing to have is a general mapping from long names of viewers to short names of icons. But while I was at this hack, I found something useful to do.)
Most of the time, a user is working in a directory below her home directory, e.g. ``///Users/Her.pa/''. (Heathens will argue that ``///'' is a perfectly good home directory on a personal machine, but heathens will argue a lot of things.) The authors of the CommandTool borrowed a lot of nifty ideas from other command interpreters, but not an abbreviation for a user's home directory. Historically, the user's home directory has been abbreviated as ``~/'', so that's what I chose. If you are running WorkingDirectory, when a CommandTool viewer is closed, the icon will show just the working directory, and an abbreviation if that directory is inside your home directory.
A caveat: since the working directory commands are necessary in a CommandTool when you full boot your machine, these commands are considered ``part of the release''. It's also considered potentially dangerous to go replacing parts of the release. It's your choice, you either run WorkingDirectory or you don't. If there were a programmer's interface to the working directory operations, life might not be easier, but it would feel safer.
The Stack of Working Directories
The authors of the CommandTool put in commands to manipulate a stack of working directories such that the top of the stack was the current working directory. That's convenient when you decide to go work on something else but don't want to lose your place. (The stack is a different model from just starting up a whole new CommandTool, since it remains ordered, whereas lots of CommandTools just get confusing.) Of course, in addition to pushing directories on to the stack and popping them off, one would like to print out the stack, and roll the stack so a given entry appears at the top (and thus is the current working directory. WorkingDirectory provides commands for printing and rolling the stack.
2. How to Use WorkingDirectory
CommandTool Commands reimplemented by WorkingDirectory
Below is a list of commands implemented by the standard CommandTool that are reimplemented by WorkingDirectory. Nothing has changed in the semantics of these commands (I hope), except that some of the short commands print directories using an abbreviation for a user's home directory, and the one's that change the current working directory label the iconic CommandTool with a short form of the CommandTool herald.
PrintWorkingDirectory
PWD
Both of these commands print the long form of the current working directory.
ChangeWorkingDirectory [directory]
CD [directory]
Both of these commands change the current working directory to the given directory. If no directory is given, the current working directory is changed to the user's home directory. The abbreviated form of the command prints the abbreviated form of the new current working directory.
CDR [directory]
This command changes the current working directory to the given directory within the root directory (e.g., ``///''). If no directory is given, the current working directory is changed to the root directory.
PushWorkingDirectory [directory]
Push [directory]
Both of these commands push the given directory onto the stack of working directories, making that directory the current working directory. If no directory is given, the users home directory is pushed onto the stack. The abbreviated form of the command prints the abbreviated form of the new current working directory.
PushR [directory]
This command pushes the given directory within the root directory onto the stack of working directories, making that directory the current working directory. If no directory is given, the root directory is pushed onto the stack.
PopWorkingDirectory
Pop
Both of these commands pop the current working directory off the stack of working directories, making the underlying directory the current working directory. If there is no underlying directory on the stack, nothing happens. The abbreviated form of the command prints the abbreviated form of the new current working directory.
New Commands provided by WorkingDirectory
Below is a list of new commands registered by WorkingDirectory.
PrintDirectoryStack
PDS
Both of these commands print the stack of working directories, with the the top of the stack (the current working directory) on the left. The abbreviated form of the command prints the abbreviated form of the directories on the stack.
RollDirectoryStack [cardinal]
RollDS [cardinal]
Both of these commands roll the directory stack so that the directory the given cardinal number of entries down becomes the top of the stack (and thus is the current working directory). If no cardinal is given, 1 is assumed. The new current working directory is printed. The abbreviated form of the command prints the abbreviated form of the new current working directory.
3. Programmer's Interface
Programmer's interface, what programmer's interface. Really, someone should make up a programmer's interface for the working directory hacking stuff in the original CommandTool, so clients (like me) could write new user and programmer interfaces on top of it. But the CommandTool is ``part of the release''. Sigh.
The abbreviation for the user's home directory can be queried and changed. There are two routines
GetHomeDirectoryAbbreviation: PROCEDURE [] RETURNS [Rope.ROPE];
SetHomeDirectoryAbbreviation: PROCEDURE [new: Rope.ROPE] RETURNS [old: Rope.ROPE];
that can be called (e.g., from the interpreter) to discover and change the abbreviation.