Related: Why is my bash prompt getting bugged when I browse the history?

History looks like:

 1831  git remote -v
 1832  gs 
 1833  gd 
 1834  gc -am 'moved apsum options etc to their own file
set routes to allow cors
changes to the apsum pull ' 
 1835  git push
 1836  reset
 1837  history
 1838  __git_ps1
 1839  reset
 1840  history
 1841  Kill 99894
 1842  history

g* are all aliases for git commands. When I scroll through history it's all fine, until I get to number 1833 (underscore denotes cursor position):

$ gd _
[ up arrow]
$ gds_
[up arrow]
$ gdit remote -v_

I figured it was because of non-printing characters in my PS1 but I've bracketed all those out:

PS1="\n\[$FCYN\]\$(date +%H:%M:%S) \w\[$IGreen\]\$(__git_ps1)\[$Black\] $ \[$DarkGray\]"

Did I miss something? Is this just something that happens when you have multiline commit messages?

edit: my final solution is too large to put into a comment:

export PS1="\\n\[\033[38;5;246m\]\u@\[$(tput sgr0)\]\[\033[38;5;245m\]\h\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]\[\033[38;5;28m\]\w\[$(tput sgr0)\]\[\033[38;5;15m\]\[$(tput sgr0)\]\[\033[38;5;2m\]`__git_ps1`\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]\[\033[38;5;90m\]\t\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]\[\033[38;5;232m\]\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]\n\[$(tput sgr0)\]\[\033[38;5;0m\]\\$\[$(tput sgr0)\] "

Which seems crazy but it produces a nice prompt with the git branch and colors that are easy to read on a light background (which you can't see here):

collumj@machineName ~ (dev) 17:35:42  

Many thanks to http://bashrcgenerator.com/.

  • It's not clear how to reproduce this.
    – chepner
    Nov 3, 2015 at 23:26
  • gc is an alias for git commit; does that help?
    – jcollum
    Nov 4, 2015 at 0:09
  • The display goes off by one character, and your prompt begins with one character \n that's not enclosed in brackets. If bash is not clever enough to recognize escape sequences, probably it's not clever enough to recognize that newline as special either, and it counts it in the number of columns advanced. Try putting that \n inside \[ \], does this help?
    – egmont
    Nov 5, 2015 at 21:40

1 Answer 1


"Everything" is bracketed, but there are several unknowns. Since the column is shifted to the right, that implies that something is sending text that bash does not notice.

While it is possible that a locale mismatch could do this, you likely would notice that.

I would check and ensure that your configuration is not using the color feature of __git_ps1. According to Fedora that invokes a script named git-prompt.sh, which in turn (if you have set GIT_PS1_SHOWCOLORHINTS) can send escape sequences which could confuse bash regarding the actual column.

  • I think you were right. SHOWCOLORHINTS was off but reverting to a more simple prompt fixed the issue. The prompt that I settled on: PS1=' __git_ps1 "\w" " $(date +%H:%M:%S) $ " '
    – jcollum
    Nov 4, 2015 at 16:44
  • Just reading the git-prompt.sh script, I didn't see a problem, but there wasn't much else to point to (testing the rest locally for syntax, etc). Nov 4, 2015 at 22:05
  • I solved this by using a prompt generator website. Works great. See my edit. You get the answer by default.
    – jcollum
    Nov 6, 2015 at 1:39

You must log in to answer this question.

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