git-aware-prompt
git-aware-prompt copied to clipboard
Issue in mac command
Mac OS X
export PS1="\u@\h \W \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ "
Sq brackets are missing around $git_branch and $git_dirty
\[$txtcyn\]\[$git_branch\]\[$txtred\]\[$git_dirty\]\[$txtrst\]\$
Square brackets are needed for non-printing characters (the colour codes). They will prevent the terminal from counting those characters when calculating the number of columns.
For characters which are displayed, the terminal needs to count them, so I don't think they should be in square brackets.
Was there any bug you experienced related to this?
Super late to the thread. I was also having an issue where the variable $git_branch
was being displayed as text (e.g. $git_branch) instead of the actual branch name.
awebdeveloper's solve made it work.
Can you post the prompt(s) that worked and didn't work for you? Putting \[
and \]
around printable text like $git_branch
is simply not correct.
Sure,
My current working ps1 export
export PS1='\e[0;32m\t\e[m \e[0;34m\u\e[m \w \e[0;35m\[$git_branch\]\e[m\nλ: '
and the previous export (that was not working but now is, likely user error) export PS1='\e[0;32m\t\e[m \e[0;34m\u\e[m \w \e[0;35m$git_branch\e[m\nλ: '
as I said, now both of these exports work correctly. when I set this up I must have forgotten to source or restart my session.
It looks like the confusion has arisen from using '
instead of "
for the prompt string.
If you use "
then \$
is needed.
If you use '
then $
is needed.
But in either case, square brackets are not desirable around visible text.
\[$git_branch\]
should just be $git_branch