Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a problem with the bash prompt. When I type a command that exceeds the length of the width of the screen it continues on the same line and overwrites what I have written, and then continues on line 2 afterwards.

This is my PS1:

PS1="\$(git_prompt) ${BIWhite}\W${Color_Off} → "

The variables


And then the script for git_prompt:

git_prompt() {
local g="$(__gitdir)"
if [ -n "$g" ]; then
    local MINUTES_SINCE_LAST_COMMIT=`minutes_since_last_commit`
    if [ "$MINUTES_SINCE_LAST_COMMIT" -gt 30 ]; then
        local COLOR=${BRed}
    elif [ "$MINUTES_SINCE_LAST_COMMIT" -gt 10 ]; then
        local COLOR=${BIYellow}
        local COLOR=${BGreen}
    local SINCE_LAST_COMMIT="${COLOR}$(minutes_since_last_commit)m${Color_Off}"
    # The __git_ps1 function inserts the current git branch where %s is
    local GIT_PROMPT=`__git_ps1 "(%s|${SINCE_LAST_COMMIT})"`
    echo ${GIT_PROMPT}

Appreciate all help! Thanks!

share|improve this question

Characters that doesn't move the cursor has to be enclosed between \[ and \] in PS1, otherwise bash thinks the prompt is longer than it actually is. And due to the way this variable is used, you can't have a function emmiting colored text as you can't escape it properly.

See for more explanation.

share|improve this answer

Your Answer


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.