I've googled around quite a bit on this problem and found a few related problems, like this one: Terminal prompt not wrapping correctly.
My problem is that bash doesn't calculate the length of the prompt correctly, which messes it up when I do things like ctrl-r or ↑ to scroll through history. This is basically how it should look (without colors).
✔ name@machine ~
01:09 $
When I for example scroll through previous commands with up-arrow, some character gets stuck in the prompt:
✔ name@machine ~
01:09 $m
Sometimes I also get other weird behaviour, like some of the prompt being overwritten (it all goes away when I reload it). My prompt looks like this:
GIT_PROMPT_START_USER="\n_LAST_COMMAND_INDICATOR_ \[$Magenta\]\u\[$Orange\]@\[$White\]\h \[$Yellow\]\[$PathShort\]\[$ResetColor\]"
GIT_PROMPT_END_USER="\n\[$Blue\]$Time12a\[$ResetColor\] $ "
I use something called git-bash-prompt
: >https://github.com/magicmonty/bash-git-prompt>.
I think what is messing it up is the time variable, which is defined in another file:
Time12a="\$(date +%H:%M)"
I've tried both \[$Time12a\]
and $Time12a
in GIT_PROMPT_END_USER
, but none of them seem to work. My guess is that bash calculates it wrong because $Time12a
represents 5 characters (hh:mm).
How does bash calculate the length of this? Is it possible to explicitly set the length for bash? Answers very appreciated!
$PathShort
from the length calculation (it's wrapped in\[…\]
). Have you checked if the prompt length offset differs when$ShortPath
is longer than one character? – n.st Jul 22 '15 at 08:30