I'm using bash as my shell and iTerm2 build 3.3.1 as my terminal emulator on Mac OS X 10.14.6 Whenever I use a type a long command, iTerm window overwrites my current line with the new symbols even though if I type proper command and run it, it runs successfully meaning, error is only in displaying command, not storing it. This also happens sometimes when I exit vim. Some of the buffer remains on screen, but my window is on shell, not on vim. This mainly happens when I use ctags and cscope. Screenshots of a long command and exiting vim are attached.

Please suggest some solution.

long command in bash (shell)

exiting vim

UPDATE 1: I figured out that bash was misbehaving in case of commads because for color coding in PS1, I used \e[....m type of format. When I replaced with \[...\] then bash prompt issue got solved. I don't know why did it happen. Also issue about clearing shell buffer after exiting vim still happens (image 2).. any help regarding these would be helpful. Thanks!

  • I have figured out that it might be issue of custom PS1 which I'm using in my .bash_profile which goes like export PS1="\e[40;0;31m[\[\033[36m\]\u \[\033[33;1m\]\w \e[0;32m\$git_branch\e[40;0;31m] \[\033[m\]$ " (here git_branch is a custom function used to show my github branch). Can I add something to it so that new line uses \r\n to go to next line instead of just \r – Chinmay Aug 13 '19 at 10:56
  • 1
    This issue is happening due to presence of \e...m type of color formatting in PS1. Changing \e....m type to \[.....\] solves my bash issue. Altough not clear why this change is solving my problem – Chinmay Aug 13 '19 at 11:25
  • Hi @Chinmay, I had a similar issue related with a misspelling on my custom PS1 definition. Thank you so much! 🙂 – garciparedes May 3 at 8:52

Your Answer

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

Browse other questions tagged or ask your own question.