Skip to content

Instantly share code, notes, and snippets.

@gomezcabo
Last active February 8, 2018 13:50
Show Gist options
  • Save gomezcabo/b513e0cda7131b5d5751dbcfb1858ad6 to your computer and use it in GitHub Desktop.
Save gomezcabo/b513e0cda7131b5d5751dbcfb1858ad6 to your computer and use it in GitHub Desktop.
function my_git_prompt() {
tester=$(git rev-parse --git-dir 2> /dev/null) || return
INDEX=$(git status --porcelain 2> /dev/null)
STATUS=""
# is branch ahead?
if $(echo "$(git log origin/$(git_current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_AHEAD"
fi
# is anything staged?
if $(echo "$INDEX" | command grep -E -e '^(D[ M]|[MARC][ MD]) ' &> /dev/null); then
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_STAGED"
fi
# is anything unstaged?
if $(echo "$INDEX" | command grep -E -e '^[ MARC][MD] ' &> /dev/null); then
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_UNSTAGED"
fi
# is anything untracked?
if $(echo "$INDEX" | grep '^?? ' &> /dev/null); then
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED"
fi
# is anything unmerged?
if $(echo "$INDEX" | command grep -E -e '^(A[AU]|D[DU]|U[ADU]) ' &> /dev/null); then
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_UNMERGED"
fi
if [[ -n $STATUS ]]; then
STATUS=" $STATUS"
fi
echo "$ZSH_THEME_GIT_PROMPT_PREFIX$(my_current_branch)$STATUS$ZSH_THEME_GIT_PROMPT_SUFFIX"
}
function my_current_branch() {
echo $(git_current_branch || echo "(no branch)")
}
function ssh_connection() {
if [[ -n $SSH_CONNECTION ]]; then
echo "%{$fg_bold[red]%}(ssh) "
fi
}
#local ret_status="%(?:%{$fg_bold[green]%}:%{$fg_bold[red]%})$%{$reset_color%}"
local ret_status="%(?:%{$fg_bold[green]%}:%{$fg_bold[red]%})$%{$reset_color%}"
#PROMPT=$'\n%~:$(my_git_prompt) \n[${ret_status}] %# '
#PROMPT=$'%{$fg[magenta]%}\n%T\n%{$fg_bold[blue]%}%~%{$reset_color%}$(my_git_prompt)\n[${ret_status}] %# '
#PROMPT=$'%{$fg[magenta]%}\n%T\n%{$reset_color%}[${ret_status}] %{$fg[green]%}%n@%m:%{$fg_bold[blue]%}%~%{$reset_color%}$(my_git_prompt)\n $ '
PROMPT=$'%{$fg_bold[black]%}\n[%W %T]\n%{$fg[green]%}%n@%m:%{$fg[blue]%}%~%{$reset_color%}$(my_git_prompt)\n${ret_status} '
ZSH_THEME_PROMPT_RETURNCODE_PREFIX="%{$fg_bold[red]%}"
#ZSH_THEME_GIT_PROMPT_PREFIX=" $fg[white]‹ %{$fg_bold[yellow]%}"
#ZSH_THEME_GIT_PROMPT_PREFIX=" $fg[white]  %{$fg[yellow]%}"
ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg_bold[white]%}[%{$fg_bold[yellow]%}"
ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg_bold[magenta]%}↑"
ZSH_THEME_GIT_PROMPT_STAGED="%{$fg[green]%}●"
ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg[red]%}●"
#ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[white]%}⛊"
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[white]%}●"
ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg_bold[red]%}✕"
#ZSH_THEME_GIT_PROMPT_SUFFIX=" $fg_bold[white]›%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$fg_bold[white]%}]%{$reset_color%}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment