Answers for "add git branch name to terminal prompt"

4

git branch in my bash prompt

parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "
Posted by: Guest on May-07-2020
0

add git branch name to terminal prompt

in your terminal, type, vi ~/.zshrc
copy and paste this code below
exit.
refresh your terminal with source ~/.zshrc

function parse_git_branch() {
    git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}

COLOR_DEF=$'\e[0m'
COLOR_USR=$'\e[38;5;243m'
COLOR_DIR=$'\e[38;5;197m'
COLOR_GIT=$'\e[38;5;39m'
setopt PROMPT_SUBST
export PROMPT='${COLOR_USR}%n ${COLOR_DIR}%~ ${COLOR_GIT}$(parse_git_branch)${COLOR_DEF} $ '
Posted by: Guest on July-13-2021

Code answers related to "add git branch name to terminal prompt"

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language