Boosting your console skills

In this little blog post I will share my tips on improving the console with:
  • Better history management
  • Much better completion

These tips work on any Mac OS X, BSD or Linux system. They are aimed towards Bash - which is a standard on most UNIX systems.

Improving the history

The problem with default Bash configuration is that the history is written only when you close a console window. This is a problem if you have 2 windows: They won't share the history and they will eventually override each others history.

This is a quick fix, open up your ~/.bashrc (or ~/.bash_profile) and add this:

#Bash should append rather than overwrite the history
shopt -s histappend

#When displaying the prompt, write the previous line to disk
PROMPT_COMMAND='history -a'

That's it for history.

If you want real comfort here is some extra configuration that I also use:

#Ignore small typos in directory names
shopt -s cdspell

#Ignore case when completing
set completion-ignore-case on

#When listing possible file completions, put / after directory names and * on files
set visible-stats on

Setting up smart completion

You can search in your history by pressing CTRL-R, here is an example of that:

CTRL-R off

One can do much better completion than CTRL-R. Here is an example of how I use up and down arrows to complete from history:

UpDown off

To get this functionality, paste this into your .inputrc:

#Move in history using up and down arrows
"\e[A": history-search-backward
"\e[B": history-search-forward                                                    

#On tab show completion
set show-all-if-ambiguous on

Update your ~/.inputrc and launch a new terminal window, now you can use up and down arrows smartly!

If you have any kick-ass console-improvement tips, then post them as comments.

Code · Tips 15. Nov 2006
© Amir Salihefendic. Powered by Skeletonz.