Tuesday, May 7, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1650  / 1 Year ago, thu, march 23, 2023, 12:07:30

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"

More From » bash

 Answers
5

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.


[#32723] Friday, March 24, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nsuainner

Total Points: 141
Total Questions: 102
Total Answers: 109

Location: Maldives
Member since Sat, Jan 29, 2022
2 Years ago
;