Skip to content

Add current Git Branch in the prompt string #2

@SolaireJS

Description

@SolaireJS

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions