Skip to content

Instantly share code, notes, and snippets.

@jeffreytgilbert
Created March 18, 2014 20:07
Show Gist options
  • Save jeffreytgilbert/9628381 to your computer and use it in GitHub Desktop.
Save jeffreytgilbert/9628381 to your computer and use it in GitHub Desktop.
# oh-my-zsh Zen Theme
### Git
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[green]%}%{$reset_color%}%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_no_bold[white]%}☁%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg_no_bold[magenta]%}▴%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_BEHIND="%{$fg_no_bold[magenta]%}▾%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_STAGED="%{$fg_no_bold[green]%}✚%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg_no_bold[yellow]%}⚡%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_no_bold[red]%}✖%{$reset_color%}"
zen_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/}"
}
zen_git_status () {
_INDEX=$(command git status --porcelain -b 2> /dev/null)
_STATUS=""
if $(echo "$_INDEX" | grep '^[AMRD]. ' &> /dev/null); then
_STATUS="$ZSH_THEME_GIT_PROMPT_STAGED$_STATUS"
fi
if $(echo "$_INDEX" | grep '^.[MTD] ' &> /dev/null); then
_STATUS="$ZSH_THEME_GIT_PROMPT_UNSTAGED$_STATUS"
fi
if $(echo "$_INDEX" | grep -E '^\?\? ' &> /dev/null); then
_STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$_STATUS"
fi
if $(echo "$_INDEX" | grep '^UU ' &> /dev/null); then
_STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$_STATUS"
fi
if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then
_STATUS="$ZSH_THEME_GIT_PROMPT_STASHED$_STATUS"
fi
if $(echo "$_INDEX" | grep '^## .*ahead' &> /dev/null); then
_STATUS="$ZSH_THEME_GIT_PROMPT_AHEAD$_STATUS"
fi
if $(echo "$_INDEX" | grep '^## .*behind' &> /dev/null); then
_STATUS="$ZSH_THEME_GIT_PROMPT_BEHIND$_STATUS"
fi
if $(echo "$_INDEX" | grep '^## .*diverged' &> /dev/null); then
_STATUS="$ZSH_THEME_GIT_PROMPT_DIVERGED$_STATUS"
fi
if [ ${#_STATUS} -eq 0 ]; then
_STATUS="$ZSH_THEME_GIT_PROMPT_CLEAN"
fi
echo $_STATUS
}
zen_git_prompt () {
local _branch=$(zen_git_branch)
local _status=$(zen_git_status)
local _result=""
if [[ "${_branch}x" != "x" ]]; then
_result="$_status $ZSH_THEME_GIT_PROMPT_PREFIX$_branch$ZSH_THEME_GIT_PROMPT_SUFFIX"
fi
echo $_result
}
zen_path_prompt () {
local _branch=$(zen_git_branch)
local _status=$(zen_git_status) # if i decide to change the path color, i can use this to see its status
local _result=''
if [[ "${_pwd}x" != "x" ]]; then
unhash _pwd
fi
if [[ "${_branch}x" != "x" ]]; then
# this is git, so take the top level path in git and nuke it from the cwd
# local _rwt=$(git rev-parse --show-toplevel)
# local _rwtlen=${#_rwt}
# local _len=$(expr ${#PWD} - $_rwtlen)
# _result=${PWD:$_rwtlen:$_len}
local _origin=$(git config --get remote.origin.url)
local _limit=$(expr ${#_origin} - 4)
_result=$(git rev-parse --show-prefix)
# if [[ "${_result}x" == "x" ]]; then
# _result="/"
# fi
_result="%{$fg[yellow]%}${_origin:0:$_limit}/%{$fg_bold[yellow]%}$_result%{$reset_color%}"
else
_result="%{$fg_no_bold[cyan]%}%~"
fi
echo $_result
}
if [[ "%#" == "#" ]]; then
_LIBERTY="%{$fg[red]%}#" # this might be root
else
_LIBERTY="%{$fg[green]%}$" # this is normal
fi
_LIBERTY="$_LIBERTY%{$reset_color%}"
zen_precmd () { # break a line so its less crowded looking
echo
}
# setopt prompt_subst
PROMPT='$(zen_path_prompt) $_LIBERTY '
RPROMPT='$(zen_git_prompt) %{$fg_bold[white]%}!%h%{$reset_color%}'
autoload -U add-zsh-hook
add-zsh-hook precmd zen_precmd
@jeffreytgilbert
Copy link
Author

still want to incorporate something like this in https://github.com/olivierverdier/zsh-git-prompt

@jeffreytgilbert
Copy link
Author

Sample for adopters
http://cl.ly/image/3Z2j2d141y03

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment