by kazinator · 10y ago · 0 comments
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".
$ 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."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.