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.
$ pwdThere's a "not seeing the forest for the trees" joke in here somewhere.
/home/jsh/work/Hello/foo/bar/mumble/frabitz
$ cd ${PWD/Hello/Goodbye}
$ pwd
/home/jsh/work/Goodbye/bar/mumble/frabitz
No comments:
Post a Comment