bash-prompt-generator icon indicating copy to clipboard operation
bash-prompt-generator copied to clipboard

Add current Git Branch in the prompt string

Open SolaireJS opened this issue 3 years ago • 0 comments

Hello

Presently the prompt string generated lack option of adding a Current Git Branch in the prompt string for display in the Bash prompt. After some fiddling, I was able to get it working. We just need to add the char sequence for displaying current Git Branch in the prompt string in .bashrc file.

For example(Fiery Orange) :

#GIT_BRANCH='[\033[38;5;12m]$(git branch 2> /dev/null | sed -e '/^[^]/d' -e 's/ (.*)/(\1)/')' export PS1="[\e[38;5;196m]\u[\e[38;5;202m]@[\e[38;5;208m]\h [\e[38;5;220m]\w ${GIT_BRANCH} [\033[0m]$ "

Also to remove the redundant space before $ and cwd in prompt add this before ${GIT_BRANCH}: [$(tput sgr0)] So, finally my PS1 in .bashrc looks like:

export PS1="[\e[38;5;196m]\u[\e[38;5;202m]@[\e[38;5;208m]\h [\e[38;5;220m]\w [$(tput sgr0)]>[\033[38;5;12m]${GIT_BRANCH}[\033[0m]$ "

Hope it helps!

SolaireJS avatar Nov 04 '22 06:11 SolaireJS