Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What in PS1 is causing my Terminal.app commands to get stuck on the screen?

When cycling through statements entered to the console, I occasionally find that the text I entered isn't refreshed and the prompt is moved to the right.

My original, intended prompt: http://cl.ly/image/04080N260L1V.

What happens after hitting the Up and Down arrows about a dozen times: http://cl.ly/image/1n3S2K31340R.

In case the screenshots aren't clear, the underlined text (in this case, "vim ~/.bas") is getting "added" to the prompt. I can't delete it out. However, if I delete as much as I can, clearing any text after the prompt, and hit Enter, I'm greeted with my clean, original prompt again: http://cl.ly/image/2O1h1Z2y0n2I.

Here's what ~/.bash_profile contains:

# Simpler bash prompt in Terminal.app
promptColor="\e[1;34m"
endColor="\e[m"
#export PS1='\e[0;36m\w$ \e[0m'
export PS1="$promptColor\w$ $endColor"

# Syntax highlighting for commands like `ls` and such
alias ls="ls -G"

# PATH ammendment to put Homebrew-installed apps in front of system-provided ones
homebrew=/usr/local/bin:/usr/local/sbin:/usr/local/share/npm/bin
export PATH=$homebrew:$PATH

I've narrowed the culprit down to the PS1 variable. (You can see I've tried this a few different ways.) Based on what I've read, I'm using the color codes correctly.

Any help would be fantastic. Thanks.

like image 307
ele Avatar asked Dec 09 '25 06:12

ele


1 Answers

This is a FAQ. In order for Bash to be able to compute the display length of the prompt correctly, any non-printing sequences such as color codes need to be inside a \[...\] sequence.

like image 70
tripleee Avatar answered Dec 10 '25 20:12

tripleee