How do I make bash reverse-search work in Terminal.app without it displaying garbled output?

StackOverflow https://stackoverflow.com/questions/35563

  •  09-06-2019
  •  | 
  •  

Question

Using Terminal.app on OS X 10.5, often you see the commands get garbled when you do a reverse-search with Bash. Is there some kind of termcap or perhaps a bash shopt command that can fix this? It is very annoying.

Steps to reproduce: Open Terminal.app, reverse-search to a longish command. Hit <ctrl>-E once you've found the command. The cursor goes to the end of the line, but the display doesn't update.

I'm guessing this is some kind of problem with the readline library on OS X. It's more of a problem with updating the cursor position after a search than anything else. Basically, ctrl-a and ctrl-e tend to break the search output.

os x terminal failure image http://involution.com/images/osxterminal.png

In the above, the first part of the command should be displayed, and the cursor should be at the end of the line, but it isn't. You literally can't see what you're editing when this happens.

Was it helpful?

Solution

I was able to set my TERM to xterm instead of xterm-color and it solves the problem. (export TERM=xterm).

OTHER TIPS

You may want to look at this post.

bash-prompt-in-os-x-terminal-broken

I had the same problem and it had to do with the PS1 variable. Let me know if this helps.

If the prompt has colors, then this is an acknowledged bug.
See bug report msg#00019.

I've encountered this bug, and while I don't know how to solve it, you can work around it by pressing <down><up>

Not sure whether this is the problem here, but a very common cause of a messed up screen in bash (with any terminal emulator, not just Terminal.app) is the window being resized.

Bash will read the window size when it starts up, and then assume it hasn't changed. When the window is resized a signal will be sent to whatever app is currently reading from the console. If this isn't bash (because you're running a text editor at the time, perhaps), then bash won't know about it.

Solution in this case is to resize the window again so that bash gets the signal and notices the new size.

I can't reproduce this, hitting either Ctrl+E, Ctrl+A or the arrow keys updates the command line correctly. Are you running 10.5.4? Is it perhaps a bug in earlier versions?

In worst case, you could launch the X server (somewhere under utilities) and launch a real xterm.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top