Linux/Unix users spend a lot of time changing directories. Why isn't cd
more helpful? Why is there no "recent directories" list? (There is, but it's hidden away and hard to discover and use) Why can't it keep track of my favorites? Why do I spend so much time in a loop of "type a few chars, hit tab" until I get back to the same place I've been 100 times before?
While it's true that a single directory change is usually quick and relatively painless, there's two dark truths waiting to be noticed:
- One changes directories many times a day, often revisiting the same folders repeatedly. This is annoying and more time-consuming than we'd like to admit.
- Some directories are buried deep in a tree and... tell me again why do I have to spend so much of my life seeking them out?
cd++
is all about reducing the friction of the humble directory change command in bash
. It's not sexy, it doesn't involve machine learning or distributed edge-network content optimization. Nobody ever got rich or famous by making it easier to change directories. This is just a few simple observations, a bit of shell script and Python, and many years of suffering the annoyance of entering commands like this, over and over each day:
cd ~/my-project/base/src/include/lxv/ver102-32992/imports/__generated__/foo
This tool replaces the default cd
behavior with something that works the same way for the most common and ordinary cases, but has magical powers beyond that:
-
Add a long dir to the index:
tjoe@my-pc:.../etc$ cd -a /home/tjoe/projects/fishhead/common/jsvsa/build/etc added/updated to /home/tjoe11/.tox-index:1
Afterwards, you can go back to that dir with just
cd jsv
-- or any unique sequence of chars which match the directory name -
Quick resolution of ambiguous dir names: If you have multiple directories in your index which match the
cd [arg]
search text, cd++ will present the choices and you can choose the correct one with minimal keyboard entry: -
Many other handy features (see usage examples below or run
cd --help
)
curl -L https://github.com/sanekits/cdpp/releases/download/1.0.0/cdpp-setup-1.0.0.sh \
-o ~/tmp$$.sh && bash ~/tmp$$.sh && rm ~/tmp$$.sh
-
Download the latest version of
cdpp-setup-1.0.0.sh
-
Run the self-extracting setup:
user@laptop$ cd ~/Downloads && ./cdpp-setup-1.0.0.sh
- Examine and customize
~/.cdpprc
for config details
There's four strategies combined in cd++
:
- Be smart about
CDPATH
and have some helpers; - Use
pushd
automatically when it makes sense to do so; - Provide aliases to speed up dumb stuff (e.g.
cd ../../../
); - Use an index to track long/obscure paths that are often project-specific
For a user willing to do a bit of mindset-and-habit-changing, cd++
can greatly reduce the effort spent moving around the file system, freeing up time for more interesting work.
cd /usr/bin
--> Nothing new here.cd
still works as expected, whenever practical.cd Down<tab>
--> Issued from 10 levels deep, let's go up to ~/Downloads without typing the~/
or the full dir name. LetCDPATH
and autocomplete do what they're good at..3
--> Don't ever type../../../
again. There's aliases for.1
thru.6
. (Why isn't this built-in tobash
?)dirs
--> List contents of bashDIRSTACK
and choose one of the recent entries to go back there.cd site nsmith
--> For more obscure (but indexed!) project-specific dirs, first do a smart search for*site*
and then another smart search for the sub-indexed directory matching*nsmith*
. You can have as many indexes as you like.
The default top-level index is~/.tox-index
. You decide what gets indexed. Ifcd
can't resolve its argument withCDPATH
, it forwards the command totox
, which is a python-powered index search and maintenance utility.
Iftox
finds multiple candidate matches, they're presented to the user for quick-pick menu selection.
cd++
usespushd
automatically for "more distant" moves, so you can get back withpopd
(or the alias.p
)cd --help
can be used for quick command / option reminderscdpath
,cdpath_add
, andcdpath_reset
streamline maintenance ofCDPATH
- If you think
cd
is doing the wrong thing, runbuiltin cd <args>
to see ifbash
agrees with you. to
has its own--help
and can be used independently ofcd++
- The comments in
~/.cdpprc
can help you optimize for your working preferences.