With the help of the obnoxious desire to be as efficient as possible when using the command line, I’ve browsed the Internet looking for new ways of achieving a new level in geekdom.
As such, I’ve come across some interesting features of Bash that I’m currently using (quite proficiently).
The first one is the CDPATH Bash variable. If you do a man bash and search for it, it’s quite clear what it does. It allows you to specify additional folders (search paths) where the cd command should look into. The same manual page states, when talking about cd “The variable CDPATH defines the search path for the directory containing dir. Alternative directory names in CDPATH are separated by a colon (:)”. How’s this helpful? For example I have a folder $HOME/school/current/ where all school related folder reside. I simply add that folder to the CDPATH and, for example, wherever I call cd so from, it changes to $HOME/school/current/so.
Here’s a sample run scenario on my laptop
razvan@valhalla:~$ echo $CDPATH
razvan@valhalla:~$ cd so
razvan@valhalla:~/school/current/so$ cd p2p-next
It’s pretty neat! Whatever the current directory, if I do a cd so or cd p2p-next it gets me to the precise folder without the need to write the whole (sometimes cumbersome) path.
A minor disadvantage is that there’s no cd Bash completion for files other than those in the current directory; you have to type the whole path of a folder reachable through CDPATH. Bash completion for the cd command works for paths reachable through CDPATH, provided the bash-completion package is installed.
Of course, in order to make it persistent, you’ll have to add a line such as the one below to your ~/.bashrc file:
You can find more info by issuing a simple Google search.
The second one is the INPUTRC file. There is a global /etc/inputrc file and a per-user ~/.inputrc file. The INPUTRC file defines Bash behavior with respect to keyboard input; it’s being used by the GNU Readline Library. There are a lot of features that may be tuned using the INPUTRC file.
The ones I’m using at this point is using TAB to show all matches in case of ambiguity for completion (similar to a TAB-TAB) and ignore case for completion. So, here are my two lines of configuration:
razvan@valhalla:~$ cat ~/.inputrc
set show-all-if-ambiguous on
set completion-ignore-case on
The ability to control the Readline library through INPUTRC is cool and useful. Check the documentation for the features you’re interested in.