views:

992

answers:

2

Hi there, I found a command a couple of months ago that made my bash history auto-complete on what's already on the line when pressing the up arrow:

$ vim fi

[press up]

$ vim file.py

I'd like to set this up on my new computer, because it saves a lot of time when keeping a big history. The problem is that I can't for the life of me remember where it was mentioned and reading through endless bash references and tutorials unfortunately didn't help either. Does anybody know the command? Thanks in advance.

+9  A: 

Probably something like

# ~/.inputrc
"\e[A": history-search-backward
"\e[B": history-search-forward

or equivalently,

# ~/.bashrc
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'

Normally, Up and Down are bound to the Readline functions previous-history and next-history respectively. I prefer to bind PgUp/PgDn to these functions, instead of displacing the normal operation of Up/Down.

# ~/.inputrc
"\e[5~": history-search-backward
"\e[6~": history-search-forward

After you modify ~/.inputrc, restart your shell or use Ctrl+X, Ctrl+R to tell it to re-read ~/.inputrc.


By the way, if you're looking for relevant documentation:

Bash uses The GNU Readline Library for the shell prompt and history.

ephemient
Thanks for your answer. This does sound familiar, but unfortunately doesn't work for me. Placing it in .inputrc changes nothing and putting it in .bashrc stop the arrows from doing anything. Any ideas?
blokkie
Never mind. history-complete-* does not exist; only the history-search-* functions exist. Thanks!
blokkie
Ah, I clearly mistyped the first two examples there... the last one was correct, though. I'll fix that up.
ephemient
A: 

You may need to enabled bash completion.

Check

  • /etc/profile
  • /etc/bash.bashrc
  • ~/.bashrc

to see if any of the above files source /etc/bash_completion. i.e.

. /etc/bash_completion

If /etc/bash___completion is not sourced by any of the above files you will need to add it to one of them.

If you want all bash users on your machine to have bash completion, source /etc/bash_completion from /etc/bash.bashrc.

If it's just you who wants bash completion, source /etc/bash_completion from your ~/.bashrc.

Convict
Tab completion is nice, but not the same as history recall, which is what the original poster was asking for.
ephemient