Pareture
Published in

Pareture

Photo by Amanda Mocci on Unsplash

Simplest ZSH Prompt Configs for Git Branch Name

Goal

Configure the zsh shell prompt (default on macOS Catalina) to spit out your git branch name if you are inside a git repository with minimal effort so you can just move on to something else.

TLWR

  1. Go to the either ‘Config’ section of this post and copy the code.
  2. Paste into your ~/.zshrc file and save.
  3. Start a new shell or source ~.zshrc .
  4. Done. Forget about it. Move on with whatever you were doing before.

Context

I’ve recently started working on a MacBook Pro with macOS Catalina which ships with Z Shell instead of Bash as the default shell.

  1. The config file is ~/.zshrc instead of ~/.bashrc . Profiles can also be used (search rc vs profile for context).
  2. Different commands and options can be used to configure the prompt which are only applicable to one shell. E.g using setopt in zsh for options.
  3. The new OS and point in time can mean new versions of other utilities and dependencies which may be different than before. For example (and this isn’t specific to this OS update) many online examples make use of the function __git_ps1 which would be available by default when you install git but this has been moved and now needs to be sourced differently[0].

Config 0

Output

Config 1

Oh My Zsh

Resources

[0] https://stackoverflow.com/questions/12870928/mac-bash-git-ps1-command-not-found

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nick Gibbon

Engineering manager in cloud infrastructure, platforms & tools.