3 ms·
No tricks, just regular cd: % pwd /home/aram % cd mstate /home/aram/src/launchpad.net/juju-core/mstate % cd go/src /home/aram/go/src % cd plan9
by 4ad 14y ago
No tricks, just regular cd:
% pwd
/home/aram
% cd mstate
/home/aram/src/launchpad.net/juju-core/mstate
% cd go/src
/home/aram/go/src
% cd plan9
/home/aram/plan9
%
It uses the $CDPATH environment variable ($cdpath in rc(1)). $CDPATH is a list of places in which to search for the wanted directory. I put all the things I regularly use there, and my cds are almost always short, usually just a single name.
I don't maintain $CDPATH myself, my profile runs a one liner that descends into certain directories and constructs $CDPATH for me within the constrains of some rules (for example excludes leafs, excludes {bin,doc,pkg,test}, etc).
Finding about $CDPATH was a huge productivity boost to me, not only in time saved typing, but in allowing me to change the way I work. I now rarely care where things in the filesystem are (e.g. various source code for various software, where the build products are, etc). I used to do a lot of moving and symlinking around, to arrange stuff so I remember where I've put it and to keep paths short, but now I don't care. It could be wherever, it's just one name away. The namespace had become a big hash.
- 6ren 14y agoJust tried this to see if tab-completion works. It does (only for cd of course). BTW: what is "rc(1)"?
- 4ad 14y agoRc(1) is the Unix v10/Plan 9 shell[1] written by Tom Duff[2], of Duff's device[3] fame. Rc(1) is of course available in Unix as well, I use the port from plan9port[4]. [1] http://doc.cat-v.org/plan_9/4th_edition/papers/rc http://doc.cat-v.org/plan_9/4th_edition/papers/rc [2] http://en.wikipedia.org/wiki/Tom_Duff http://en.wikipedia.org/wiki/Tom_Duff [3] http://en.wikipedia.org/wiki/Duff%27s_device http://en.wikipedia.org/wiki/Duff%27s_device [4] http://swtch.com/plan9port/ http://swtch.com/plan9port/
- awayand 14y ago|my profile runs a one liner... what's that one liner look like?
- 4ad 14y agoI lied, seems to be 5 lines total :-) export CDPATH=.:~ cdpaths="$([ -d ~/src ] && find ~/src -mindepth 1 -type d | egrep -v '/(\.)|_[a-zA-Z0-9]' | egrep -v '(bin)|(cmd)|(doc)|(lib)|(pkg)|(test)' | xargs -n1 dirname | uniq)" for i in $cdpaths; do CDPATH=$CDPATH:$i done
- wting 14y agoThis is a pretty good solution, however there are a few things other programs add on: - $CDPATH requires manual management. You're using a line in profile, but I imagine that's limited to specific directories and creates overhead when creating new shells. - What happens with namespace collision? First entry in $CDPATH wins? - Fuzzy searching for mistyped directory names. I don't find this feature that useful personally, but was requested quite a bit by others. William (autojump maintainer)