Monday, February 11, 2008

Parallel Trees

I work in forests. I'll often have two or more, parallel, build trees that I'm doing different things in, which I need to switch among.

The Korn shell has a two-argument cd command for this kind of work.

If my two trees are ~/work/Hello/ and ~/work/Goodbye/, and I'm buried deep in
~/work/Hello/foo/bar/mumble/frabitz/ , the command
$ cd Hello Goodbye
will teleport me to ~/work/Goodbye/foo/bar/mumble/frabitz/ .

After I switched to bash, I wished, for years, that I still had this. I even wrote functions that would let cd handle two arguments, though they sometimes had subtle bugs.

Then, one day, I realized shell string substitution gives me the same thing, right out of the box.
$ pwd
/home/jsh/work/Hello/foo/bar/mumble/frabitz
$ cd ${PWD/Hello/Goodbye}
$ pwd
/home/jsh/work/Goodbye/bar/mumble/frabitz
There's a "not seeing the forest for the trees" joke in here somewhere.

No comments: