Skip to content

Instantly share code, notes, and snippets.

@Magnuti
Last active February 2, 2024 08:29
Show Gist options
  • Save Magnuti/7c892399ed5776397afca25dd9959645 to your computer and use it in GitHub Desktop.
Save Magnuti/7c892399ed5776397afca25dd9959645 to your computer and use it in GitHub Desktop.
.zshrc profile for Git autocompletion and branch name

Git autocompletion and Git branch name in Z shell prompt

autoload -Uz compinit && compinit

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

COLOR_GIT=$'%F{39}'
COLOR_DEF=$'%f'
setopt PROMPT_SUBST
export PROMPT='%~${COLOR_GIT} $(parse_git_branch)${COLOR_DEF}$ '

Screenshot 2024-02-02 at 09 14 57

Restart the shell or reload the profile by running source ~/.zshrc.

Credits

Based on this gist by reinvanoyen.

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