3 ms·
I wrote something called pcd. https://news.ycombinator.com/edit?id=10723381 https://news.ycombinator.com/edit?id=10723381 If you are currently in "a/b/c", the
by kazinator 11y ago
I wrote something called pcd.
https://news.ycombinator.com/edit?id=10723381 https://news.ycombinator.com/edit?id=10723381
If you are currently in "a/b/c", then "pcd x" will try to change to "a/x/c", "pcd x 0" to "a/b/x", "pcd x 2" to "x/b/c".
pcd is helpful if you are working in a directory tree with parallel structures. You're in "proj/parser/src" but need to be in "proj/iolib/src". Just "pcd iolib".
- 0942v8653 11y agoSounds useful. zsh has a feature for similar use cases: if you `cd dir1 dir2`, it will replace dir1 with dir2 in your path (i.e. a/dir1/c -> a/dir2/c)
- semi-extrinsic 11y agoHave you seen how zsh adds this functionality to plain cd? $ pwd /usr/share/texmf-dist/tex $ cd usr usr/local $ pwd /usr/local/share/texmf-dist/tex Edit: there is also a directory stack, and you can set zsh to always push the current dir to the stack. Then you can do cd -4 to go to the directory you were in four cd's ago.
- mtdewcmu 11y agoI made something similar to that. I also made a couple other scripts to help with navigating deep directory subtrees: "cdup" would jump to the specified ancestor directory of the CWD. So from /a/b/c/d/e, "cdup b" jumps to /a/b. This beats typing "cd ../../..", & it lends itself naturally to autocomplete. Writing this script is a piece of cake. "cdto" is roughly the inverse of "cdup". It would jump to the specified descendant of the CWD, if one exists. If there is more than one possibility, it displays a choice (using `select`). So from /a, "cdto e" might jump to /a/b/c/d/e. This entails doing a recursive directory search, which can take a little bit of time, but it can save obnoxious typing in big, nasty directory trees. Writing this script is a bit trickier. cdto also accepted a file as argument, in which case it jumped to the directory that contained that file.