3

In terminal i've changed my PS1.

I think it maybe causing issues with allowing me to hit the home button. Normally by hitting the home button it's suppose to return to the first character on the first line

my prompt file: https://raw.github.com/chrisjlee/dotfiles/master/.prompt

# Setup color Variables
#############################
STARTFGCOLOR='\e[0;36m'
STARTBGCOLOR="\e[0;32m"
ENDCOLOR="\e[0m"

export PS1="\e[0;36m\n[ $STARTFGCOLOR$STARTBGCOLOR\u@\h\e[01;35m \w $STARTBGCOLOR$STARTFGCOLOR]\e[0;32m\n\e[0;35m]$ $ENDCOLOR"

Whenever i redo the last command (by hitting the up button in terminal) and hit the home button it'll stop halfway. And then the characters will not read correctly

Has anyone else have this issue?

1 Answer 1

5

You have to wrap every color code in escaped square brackets like this: \[colorcode\].

Example:

STARTFGCOLOR='\[\e[0;36m\]'
STARTBGCOLOR="\[\e[0;32m\]"
ENDCOLOR="\[\e[0m\]"

Explanation: bash has to calculate the length of the prompt so it can place the cursor correctly when you press home. For whatever reason bash does not consider color codes as taking no space on screen. You have to explicitly tell bash that the color codes do not take up space by wraping them in escaped square brackets.

See here for more explanation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .