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"
  • did you find why this bind is broken after some commands? not necessarily top, but some commands seem to break the bind. – dashesy May 13 at 18:05
  • Top no longer does this for me, but wine dows. I do not know why it is doing it, I am not using it often enough. – sup May 14 at 19:47
  • 1
    I further searched SO, the fix is to execute reset. – dashesy May 14 at 21:32
  • Thanks, that is exactl what I needed to know! – sup May 15 at 10:51
  • if you add it as an anwser, I will accept it. – sup May 15 at 10:51
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.

| improve this answer | |
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.

| improve this answer | |
  • Hm, you mean adding "\e[5C": history-search-backward "\e[6D": history-search-forward to that file? Anywhere? I do not understand the #if – sup Jun 17 '13 at 23:31
  • Hm, it works fine in tty, the problem is with (it affects both unity and gnome shell). – sup Jun 17 '13 at 23:38
  • The #if here was mentioned in case that the inputrc file is empty. In that case you could see from my answer what to write in this file. – Wolfy Jun 18 '13 at 12:22
  • Well, editing inputrc does not change anything anyway – sup Jun 18 '13 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.