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?
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
:I prefer to bind it to Ctrl+up/down instead:
edit: To preserve ctrl+left and ctrl+right for moving back and forward in whole words, also include these lines in
~/.inputrc
file:Try hitting Ctrl + R, and typing a few letters. It works in the reverse order as well.
And don't forget the fantastic history expansion shortcuts in bash. 1
I'm posting some excerpts from the manpage, in case you haven't tattooed them on your arm (or memorized them).
I frequently use the ability to refer to the last 'word' of the previous command. E.g.,
In both cases here, the
!$
matches/foo/shmoo/adir.horribilus.foo
.1... which were taken from csh. To mitigate the scope of bash's feature theft, the bash man page says
So, it's "similar". Any of this might break in
csh
ortcsh
. Or whichever csh descendent you are not using due to the fact that it isn't as wonderful asbash
.There is an alternative similar to what @ak2 mentioned above, but you do not have to create a new .inputrc file.
Instead, if you have sudo permissions, you can enable this in the /etc/inputrc file. In this file are various keyboard settings including the history search feature (for 18.04 at least). The excerpt from /etc/inputrc is:
Simply uncomment the bottom two lines using a sudo file editor (e.g., $ sudo vim), and a new terminal session will have the history search feature (for all users).