Minimalist git prompt

3 min read

For as long as I can remember, I have had some sort of git status as part of my shell prompt.

Early on I had used the canned git prompt scripts that are floating around out there. I felt they were way too bloated with the 42-some-odd glyphs that they display to represent the state of your repository.

Fortunately, the informative git prompt for zsh was highly configurable and I was able to get customize things to my liking.

What’s my liking? Just the branch name in yellow and a red ✗ if the repository is dirty.

No arrows telling me if we’re ahead or behind. No brackets or parentheses wrapping the information. And especially no green check mark stating the obvious at all time.

Just the branch and an indicator if it’s dirty (and not when it’s clean).

My glorious prompt!

As flexible as the git prompt for zsh was, I did find myself having to hack together quite a bit to get down to the minimal git prompt I so desired.

No big deal, once it was working it was out of sight and out of mind.

Fast forward to a few weeks ago when I decided to drop zsh and go back to bash. I wanted to see if bash could once again be everything I desired in a shell.

Spoiler alert, it wasn’t and I’m back on zsh.

With that, I wanted to get my bash prompt to look and behave exactly like my zsh prompt, complete with my minimal git prompt.

I had decided to give the informative git prompt for bash and fish as shot as it was a port of the zsh git prompt that I was already familiar with.

Unfortunately, I found it be less configurable than the original and I just couldn’t get it to do what I wanted, so I gave in and ran it without much tweaking.

Arrows and glyphs and all that shit I hated.

I gave it a few days though, to see if it was going to grow on me.

And it didn’t.

At this point, I set out to get the minimalist git prompt of my dreams working without any additional dependencies in both bash and zsh.

Here’s what I came up with.

minimalist bash git prompt

RESET=$(tput sgr0)

BLUE=$(tput setaf 4)
GREY=$(tput setaf 244)
RED=$(tput setaf 1)
YELLOW=$(tput setaf 3)

git_prompt() {
  BRANCH=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/*\(.*\)/\1/')

  if [ ! -z $BRANCH ]; then
    echo -n "$YELLOW$BRANCH"

    if [ ! -z "$(git status --short)" ]; then
      echo " ${RED}✗"


minimalist zsh git prompt

git_prompt() {
  BRANCH=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/*\(.*\)/\1/')

  if [ ! -z $BRANCH ]; then
    echo -n "%F{yellow}$BRANCH"

    if [ ! -z "$(git status --short)" ]; then
      echo " %F{red}✗"

%F{244}%# %F{reset}'

As always, you can keep up with my dotfiles over on GitHub!