DEV Community

Gyowanny (Geo) Queiroz
Gyowanny (Geo) Queiroz

Posted on

Display current folder + git branch in the macOS terminal prompt

Tested on macOS Monterey 12.3.1

Add the snippet below to the bottom of the file according to your terminal version.

iTerm

Edit ~/.bash_profile

Terminal

Edit ~/.zshrc

# 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 '
Enter fullscreen mode Exit fullscreen mode

Result

Image description

Top comments (0)