Ubuntu – iPython Like Command History For Shell

bashcommand line

For those of you who don't do python programming on ubuntu, ipython is a python shell on steroids, but it has this amazing feature that it not only autcompletes based on known names (i.e. the same way bash does when you press tab), but if you start typing a command and press up, it doesn't scroll through the entire history (like bash) but only through the recent commands that started with the same string of leters.

So if you did some long command like scp -r -P 8000 -l user server.com:~/dir/to/copy ./ followed by several other commands. If you started typing scp and pressed up, bash would display the command shown before instead of just scrolling through the entire history.

Is there an extension like this for bash? or is there any shell that offers this kind of feature?

Best Answer

Bash does have that feature too, but it's not enabled by default. You can bind it to cursor up/down by sticking this into ~/.inputrc:

"\e[A": history-search-backward
"\e[B": history-search-forward

I prefer to bind it to Ctrl+up/down instead:

"\e[1;5A": history-search-backward
"\e[1;5B": history-search-forward

edit: To preserve ctrl+left and ctrl+right for moving back and forward in whole words, also include these lines in ~/.inputrc file:

# mappings for Ctrl-left-arrow and Ctrl-right-arrow for word moving
"\e[1;5C": forward-word
"\e[1;5D": backward-word
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word