Skip to content

Instantly share code, notes, and snippets.

@juliancoleman
Last active May 29, 2019 00:27
Show Gist options
  • Save juliancoleman/0c2e1eb4d898bfd915b5a1d48a909191 to your computer and use it in GitHub Desktop.
Save juliancoleman/0c2e1eb4d898bfd915b5a1d48a909191 to your computer and use it in GitHub Desktop.
ZSH_THEME_GIT_PROMPT_PREFIX=":%{$fg_bold[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[green]%}✓%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg_bold[cyan]%}▲%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_BEHIND="%{$fg_bold[orange]%}▼%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_STAGED="%{$fg_bold[green]%}●%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg_bold[yellow]%}●%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}●%{$reset_color%} "
#
# Copied from Bureau
#
bureau_git_branch () {
ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
echo "${ref#refs/heads/}"
}
bureau_git_status() {
_STATUS=""
# check status of files
_INDEX=$(command git status --porcelain 2> /dev/null)
if [[ -n "$_INDEX" ]]; then
if $(echo "$_INDEX" | command grep -q '^[AMRD]. '); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STAGED"
fi
if $(echo "$_INDEX" | command grep -q '^.[MTD] '); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNSTAGED"
fi
if $(echo "$_INDEX" | command grep -q -E '^\?\? '); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED"
fi
if $(echo "$_INDEX" | command grep -q '^UU '); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNMERGED"
fi
else
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_CLEAN"
fi
# check status of local repository
_INDEX=$(command git status --porcelain -b 2> /dev/null)
if $(echo "$_INDEX" | command grep -q '^## .*ahead'); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_AHEAD"
fi
if $(echo "$_INDEX" | command grep -q '^## .*behind'); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_BEHIND"
fi
if $(echo "$_INDEX" | command grep -q '^## .*diverged'); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_DIVERGED"
fi
if $(command git rev-parse --verify refs/stash &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STASHED"
fi
echo $_STATUS
}
bureau_git_prompt () {
local _branch=$(bureau_git_branch)
local _status=$(bureau_git_status)
local _result=""
if [[ "${_branch}x" != "x" ]]; then
_result="$ZSH_THEME_GIT_PROMPT_PREFIX$_branch"
if [[ "${_status}x" != "x" ]]; then
_result="$_result $_status"
fi
_result="$_result$ZSH_THEME_GIT_PROMPT_SUFFIX"
fi
echo $_result
}
# Uncomment to get RVM info as well
# PROMPT='%B⬡%b $(nvm_prompt_info) %B💎%b $(rvm_prompt_info) %{$fg_bold[green]%}%c%{$reset_color%}$(bureau_git_prompt)
# %B∴%b '
# Comment this out when using the PROMPT above.
PROMPT='%{$fg_bold[green]%}⬢ $(nvm_prompt_info)%{$reset_color%} %{$fg_bold[white]%}| %c$(bureau_git_prompt)
%B∴%b '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment