Skip to content

Instantly share code, notes, and snippets.

@iawaisrana
Last active July 23, 2023 18:09
Show Gist options
  • Save iawaisrana/11fe7f2ac7c666d87fa276684052208b to your computer and use it in GitHub Desktop.
Save iawaisrana/11fe7f2ac7c666d87fa276684052208b to your computer and use it in GitHub Desktop.

Add Git Branch Name to Terminal Prompt (macOS Catlina)

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

# Git branch in prompt.

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

setopt PROMPT_SUBST
export PROMPT='%F{grey}%n%f %F{cyan}%~%f %F{green}$(parse_git_branch)%f %F{normal}$%f '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment