1

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/.

jcollum
  • 1,179
  • It's not clear how to reproduce this. – chepner Nov 03 '15 at 23:26
  • gc is an alias for git commit; does that help? – jcollum Nov 04 '15 at 00: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 05 '15 at 21:40

1 Answers1

2

"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.

Thomas Dickey
  • 76,765
  • 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 04 '15 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). – Thomas Dickey Nov 04 '15 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 06 '15 at 01:39