Created
July 15, 2014 18:46
-
-
Save paulfri/5dcae5452f0141e79b27 to your computer and use it in GitHub Desktop.
paulfri.zsh-theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[blue]%}" | |
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " | |
ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg[cyan]%}▴%{$reset_color%}" | |
ZSH_THEME_GIT_PROMPT_BEHIND="%{$fg[magenta]%}▾%{$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%}" | |
theme_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/}" | |
} | |
theme_git_status () { | |
_INDEX=$(command git status --porcelain -b 2> /dev/null) | |
_STATUS="" | |
if $(echo "$_INDEX" | grep '^[AMRD]. ' &> /dev/null); then | |
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STAGED" | |
fi | |
if $(echo "$_INDEX" | grep '^.[MTD] ' &> /dev/null); then | |
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNSTAGED" | |
fi | |
if $(echo "$_INDEX" | grep -E '^\?\? ' &> /dev/null); then | |
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED" | |
fi | |
if $(echo "$_INDEX" | grep '^UU ' &> /dev/null); then | |
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNMERGED" | |
fi | |
if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then | |
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STASHED" | |
fi | |
if $(echo "$_INDEX" | grep '^## .*ahead' &> /dev/null); then | |
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_AHEAD" | |
fi | |
if $(echo "$_INDEX" | grep '^## .*behind' &> /dev/null); then | |
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_BEHIND" | |
fi | |
if $(echo "$_INDEX" | grep '^## .*diverged' &> /dev/null); then | |
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_DIVERGED" | |
fi | |
echo $_STATUS | |
} | |
theme_git_prompt () { | |
local _branch=$(theme_git_branch) | |
local _status=$(theme_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 | |
} | |
local ruby_version='' | |
if which rvm-prompt &> /dev/null; then | |
ruby_version="%{$fg[red]%}$(rvm-prompt v s)%{$reset_color%}" | |
else | |
if which rbenv &> /dev/null; then | |
ruby_version='%{$fg[red]%}$(rbenv version | sed -e "s/ (set.*$//")%{$reset_color%}' | |
fi | |
fi | |
# segments | |
local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})" | |
local user_host="%{$fg[yellow]%}%n@%m" | |
local working_dir="%{$fg[green]%}%~" | |
local systime="%{$fg[cyan]%}[%*]%{$reset_color%}" | |
# the good stuff | |
PROMPT='${user_host} ${ruby_version} ${working_dir} $(theme_git_prompt)%{$reset_color%}$ ' | |
RPS1="${return_code} ${systime}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment