Thursday, May 28, 2009

Editing Parallel Trees

Sometimes, I need to work in parallel trees -- trees with the same structure, but some important difference (different revision numbers, different compiler flags, ...). When I'm deep inside one tree, getting over to the homologous place in the other can be painful. Not only is it a lot of typing, but I'm often made aware that I should work at "Typos R Us."

The string substitution syntax ${FOO/bar/mumble}, which returns $FOO, but with mumble substituted for bar, solves my problem. For example, if I'm in the tree /home/jsh/tree1/a/b/c/d, and I want to pop over to /home/jsh/tree2/a/b/c/d, I just say

$ pushd ${PWD/tree1/tree2}
or even

$ cd ${PWD/1/2}
Presto! I'm there faster than you can say, "xyzzy." Or, at least as fast.

Not only am I in the new tree, but now pushd, with no arguments, (or cd - ) takes me back and forth.

No comments: