DEV Community

Gyowanny (Geo) Queiroz
Gyowanny (Geo) Queiroz

Posted on

4 2

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay