Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save edbritton/e4312a8d0c7938f085ede3139418ad93 to your computer and use it in GitHub Desktop.
Save edbritton/e4312a8d0c7938f085ede3139418ad93 to your computer and use it in GitHub Desktop.
Add colour and Git details to command line prompt

Add colour and Git details to Terminal prompt

Takes the default macOS zsh prompt and adds colour to the path, a branch name if present, and marks that changes are made if true.

Admittedly could probably do with some optimising.

"Installing"

Add (or create) the following to the ~/.zshrc file.

# ~/.zshrc

autoload -Uz vcs_info # enable vcs_info
precmd () { vcs_info } # always load before displaying the prompt
zstyle ':vcs_info:*' formats ' (%F{34}%{⤴%G%} %b%f)'

function parse_git_dirty {
  inside_git_repo="$(git rev-parse --is-inside-work-tree 2>/dev/null)"

  if [ "$inside_git_repo" ]; then 
    if git diff-index --quiet HEAD
    then
      echo ""
    else
      echo " ●"
    fi
  else
    echo ""
  fi
}

setopt PROMPT_SUBST
export PROMPT='%n@%m %F{220}%1~%f${vcs_info_msg_0_}%F{202}$(parse_git_dirty)%f %% '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment