This is another clone of NCD, a great tool from Norton Utilities for DOS. The main diference from other clones is that it creates a database of all the directories and uses it to speed up the search. It also rotates along the directories that match the searched pattern, if more than one exists.
NCD is the best utility I know to quickly switch from one directory to another. It was widely used in the days of MSDOS because it would allow us to move from any point in the directory tree to another leaf or node, knowing the target's name only. Since windows emerged as the replacement for DOS, NCD practically disappeared.
In Linux and UNIX I've never found any utility that could mimic the behaviour of NCD, exactly as I remember, so I searched the web and found a few clones. The best one (as far as I could find) is Fergal Goggin's one.
It implements a database files to store all the directories and speed up search. Also, if there are multiple matches to the target directory it will display them and ask the user to select the desired one. But since the match is based in a grep to the database, multiple matches will be shown if you select a node in the tree that also contains subdirectories. Look at the example picture below where I tried to move to the SDFAPI_SRC:
Even so I found this script to be the best to improve! My changes involve the last part of the script, where the user has to choose the target directory. I don't give the user the option of choosing the target directory if multiple matches are found. Instead the script rotates along the list of targets every time the user runs ncd with the same target:
I also changed the matching technique. A target only matches if it is a leaf in each path! This means that even nodes that have leafs only show up once in the target list!
Ok, without further delays here is the code!
To install it just copy the file to a directory in your path and add an alias to your startup script (.profile, .bash_profile, etc):
alias ncd='. ncd'
don't forget to replace the ncd inside single quotes with the correct file name, and then run it:
The first run will create a database in your home directory named .ncd.`uname -n`
Subsequent runs can have an argument like:
$ ncd SDF
Optionally your can recreate the database using the previous BASEDIR just by typing:
$ ncd -r
And that's it! Now navigate around!
Common problems are: an outdated tree and small database.
If your tree is outdated, just delete the database file in your home directory and re-run ncd to recreate it. From V1.8 and above you may also run ncd with the option -r.
To create a larger database with all the directories in your system change the BASEDIR variable to someting like / then delete the database file and re-run ncd to create a larger database!
Be careful because it will take a lot of time!
Check the header of each file to read the release notes in detail!
Fergal Goggin - The creator of the original script