Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add current Git Branch in the prompt string #2

Open
SolaireJS opened this issue Nov 4, 2022 · 0 comments
Open

Add current Git Branch in the prompt string #2

SolaireJS opened this issue Nov 4, 2022 · 0 comments

Comments

@SolaireJS
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant