Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.