Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zrobit/aeb09a280908c6c41bad3ac4d87cc2f2 to your computer and use it in GitHub Desktop.
Save zrobit/aeb09a280908c6c41bad3ac4d87cc2f2 to your computer and use it in GitHub Desktop.
Add Git Branch Name to Terminal Prompt (MacOS Catalina zsh)

Add Git Branch Name to Terminal Prompt (MacOS Catalina zsh)

screenshot

Open ~/.zshrc in your favorite editor and add the following content to the bottom.

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} $ '

Original gist for Bash by Jose Quintana: https://gist.github.com/joseluisq/1e96c54fa4e1e5647940

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment