Last active
November 4, 2016 23:09
-
-
Save dperrera/3a57af738ed0fee3f57e to your computer and use it in GitHub Desktop.
My personal OhMyZsh 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
local ret_status="%(?:%{$fg_bold[green]%}→:%{$fg_bold[red]%}→%s)" | |
#ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[red]%}" | |
#ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" | |
#ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%} %{$fg[yellow]%}✗%{$reset_color%}" | |
#ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%}" | |
# Adapted from code found at <https://gist.github.com/1712320>. | |
# Modify the colors and symbols in these variables as desired. | |
GIT_PROMPT_SYMBOL="%{$fg_bold[blue]%}" | |
GIT_PROMPT_PREFIX="%{$fg_bold[green]%}%{$reset_color%}" | |
GIT_PROMPT_SUFFIX="%{$fg_bold[green]%}%{$reset_color%}" | |
GIT_PROMPT_AHEAD="%{$fg_bold[red]%}ANUM %{$reset_color%}" | |
GIT_PROMPT_BEHIND="%{$fg_bold[cyan]%}BNUM %{$reset_color%}" | |
GIT_PROMPT_MERGING="%{$fg_bold[magenta]%}⚡︎ %{$reset_color%}" | |
GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}●%{$reset_color%}" | |
GIT_PROMPT_MODIFIED="%{$fg_bold[yellow]%}●%{$reset_color%}" | |
GIT_PROMPT_STAGED="%{$fg_bold[green]%}●%{$reset_color%}" | |
# Show Git branch/tag, or name-rev if on detached head | |
parse_git_branch() { | |
(git symbolic-ref -q HEAD || git name-rev --name-only --no-undefined --always HEAD) 2> /dev/null | |
} | |
# Show different symbols as appropriate for various Git repository states | |
parse_git_state() { | |
# Compose this value via multiple conditional appends. | |
local GIT_STATE="" | |
local NUM_AHEAD="$(git log --oneline @{u}.. 2> /dev/null | wc -l | tr -d ' ')" | |
if [ "$NUM_AHEAD" -gt 0 ]; then | |
GIT_STATE=$GIT_STATE${GIT_PROMPT_AHEAD//NUM/$NUM_AHEAD} | |
fi | |
local NUM_BEHIND="$(git log --oneline ..@{u} 2> /dev/null | wc -l | tr -d ' ')" | |
if [ "$NUM_BEHIND" -gt 0 ]; then | |
GIT_STATE=$GIT_STATE${GIT_PROMPT_BEHIND//NUM/$NUM_BEHIND} | |
fi | |
local GIT_DIR="$(git rev-parse --git-dir 2> /dev/null)" | |
if [ -n $GIT_DIR ] && test -r $GIT_DIR/MERGE_HEAD; then | |
GIT_STATE=$GIT_STATE$GIT_PROMPT_MERGING | |
fi | |
if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then | |
GIT_STATE=$GIT_STATE$GIT_PROMPT_UNTRACKED | |
fi | |
if ! git diff --quiet 2> /dev/null; then | |
GIT_STATE=$GIT_STATE$GIT_PROMPT_MODIFIED | |
fi | |
if ! git diff --cached --quiet 2> /dev/null; then | |
GIT_STATE=$GIT_STATE$GIT_PROMPT_STAGED | |
fi | |
if [[ -n $GIT_STATE ]]; then | |
echo "$GIT_PROMPT_PREFIX$GIT_STATE$GIT_PROMPT_SUFFIX" | |
fi | |
} | |
# If inside a Git repository, print its branch and state | |
git_prompt_string() { | |
local git_where="$(parse_git_branch)" | |
[ -n "$git_where" ] && echo "$GIT_PROMPT_PREFIX%{$fg_bold[yellow]%}${git_where#(refs/heads/|tags/)}$GIT_PROMPT_SUFFIX $GIT_PROMPT_SYMBOL$(parse_git_state)" | |
} | |
PROMPT=' | |
${ret_status}%{$fg_bold[green]%}%p %{$fg[cyan]%}%~ %{$fg_bold[blue]%}$(git_prompt_string)%{$fg_bold[blue]%} | |
%{$fg_bold[black]%}$ %{$reset_color%}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment