I'm using custom bash prompt to show git branch.
Everything is in /etc/bash/bashrc
:
function formattedGitBranch {
_branch="$(git branch 2>/dev/null | sed -e "/^\s/d" -e "s/^\*\s//")"
# tried these:
echo -e "\e[0;91m ($_branch)"
echo -e "\e[0;91m ($_branch) \e[m"
echo -e $'\e[0;91m'"($_branch)"
echo "($_branch)"
echo "$(tput setaf 2) ($_branch) $(tput setaf 9)"
printf "\e[0;91m ($_branch)"
}
# color is set before function call
PS1='\[\033[01;34m\] \[\033[0;91m\]$(formattedGitBranch) \$\[\033[00m\] '
# color is set inside function
PS1='\[\033[01;34m\] $(formattedGitBranch) \$\[\033[00m\] '
Problem is that when I set color for $_branch
in the function, my prompt will be overwritten when EOL is reached:
Tried all possible variants tput
, printf
, $''
notation.
I solved the problem by setting the colour only in PS1
:
But..
- I would like to know why it is overwriting my prompt
- How to fix this issue when function is used
I'm using Gentoo Linux. GNU bash, verze 4.2.37(1)-release (i686-pc-linux-gnu)
\[
without using\]
and it was causing a similar issue to OP. Thank you. – Quetzal