2

I have a line in my .bashrc the following line:

bind '"\e[A": history-search-backward'

that causes that when I write "abc" to command prompt and press up arrow, bash searches in history only for commands that start with "abc". All is fine until I run top (and maybe some other applications that I am not sure about, with top, I am sure) when this behaviour is reversed to normal search. However, when I run bind '"\e[A": history-search-backward' in terminal, nothing changes and I have to kill and restart the terminal to get the old behaviour back. Is there a way to reverse it (or prevent it from happening?) This happens in gnome-terminal and xterm in Unity and Gnome Shell. tty seems to be not affected.

My -bashrc on top of stok ubuntu .bashrc is this:

bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
# that behaviour is for pageup and pagedown
bind '"\e[5~": previous-history'
bind '"\e[6~": next-history'

# show possibilities if tab ambigious
set show-all-if-ambiguous on
# ignore case when completing, lets see how it works
set completion-ignore-case on


shopt -s cdspell
HISTSIZE=10000
HISTCONTROL=ignoredups
HISTFILESIZE=10001
HISTTIMEFORMAT="%h/%d - %H:%M:%S "
shopt -s histappend
PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
sup
  • 4,964

2 Answers2

1

It turns out that some misbehaving applications break the cursor mode. The symptoms are similar to when we accidentally cat a binary file to terminal.

The fix is to call reset. If Enter is also broken, then we can use Ctrl+J as also mentione here.

As to the original question of why top (or in my case some random script that uses escape characters for colorful output) breaks history-search-backward. When it is broken, you can run read and then hit the arrow keys. Usually it is \e[A but when broken it may become \eOA. So, one could map that to history-search-backward as well, but usually the terminal is not in a very usable state and reset fixes the issue.

dashesy
  • 163
0

Try edit binds in /etc/inputrc file.

I use 'history-search-backward' on all linux systems and I have no problem with top.

If you have problems with editing the file, see my answer here.

Wolfy
  • 8,050