2011-12-29 08:30:43 +08:00
|
|
|
|
function my_git_prompt() {
|
|
|
|
|
tester=$(git rev-parse --git-dir 2> /dev/null) || return
|
2024-03-26 16:55:16 +08:00
|
|
|
|
|
2011-12-29 08:30:43 +08:00
|
|
|
|
INDEX=$(git status --porcelain 2> /dev/null)
|
|
|
|
|
STATUS=""
|
|
|
|
|
|
|
|
|
|
# is branch ahead?
|
2015-06-26 03:04:01 +08:00
|
|
|
|
if $(echo "$(git log origin/$(git_current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
|
2011-12-29 08:30:43 +08:00
|
|
|
|
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_AHEAD"
|
|
|
|
|
fi
|
|
|
|
|
|
2018-07-02 02:41:52 +08:00
|
|
|
|
# is branch behind?
|
2018-07-03 23:37:18 +08:00
|
|
|
|
if $(echo "$(git log HEAD..origin/$(git_current_branch) 2> /dev/null)" | grep '^commit' &> /dev/null); then
|
2018-07-02 02:41:52 +08:00
|
|
|
|
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_BEHIND"
|
|
|
|
|
fi
|
|
|
|
|
|
2011-12-29 08:30:43 +08:00
|
|
|
|
# is anything staged?
|
2014-11-16 16:47:35 +08:00
|
|
|
|
if $(echo "$INDEX" | command grep -E -e '^(D[ M]|[MARC][ MD]) ' &> /dev/null); then
|
2011-12-29 08:30:43 +08:00
|
|
|
|
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_STAGED"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# is anything unstaged?
|
2014-11-16 16:47:35 +08:00
|
|
|
|
if $(echo "$INDEX" | command grep -E -e '^[ MARC][MD] ' &> /dev/null); then
|
2011-12-29 08:30:43 +08:00
|
|
|
|
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?
|
2014-11-16 16:47:35 +08:00
|
|
|
|
if $(echo "$INDEX" | command grep -E -e '^(A[AU]|D[DU]|U[ADU]) ' &> /dev/null); then
|
2011-12-29 08:30:43 +08:00
|
|
|
|
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() {
|
2015-06-26 03:04:01 +08:00
|
|
|
|
echo $(git_current_branch || echo "(no branch)")
|
2011-12-29 08:30:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ssh_connection() {
|
|
|
|
|
if [[ -n $SSH_CONNECTION ]]; then
|
|
|
|
|
echo "%{$fg_bold[red]%}(ssh) "
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-11 15:31:53 +08:00
|
|
|
|
function _toolbox_prompt_info() {
|
|
|
|
|
if typeset -f toolbox_prompt_info > /dev/null; then
|
|
|
|
|
toolbox_prompt_info
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-03 18:03:43 +08:00
|
|
|
|
local ret_status="%(?:%{$fg_bold[green]%}:%{$fg_bold[red]%})%?%{$reset_color%}"
|
2023-09-11 15:31:53 +08:00
|
|
|
|
PROMPT=$'\n$(_toolbox_prompt_info)$(ssh_connection)%{$fg_bold[green]%}%n@%m%{$reset_color%}$(my_git_prompt) : %~\n[${ret_status}] %# '
|
2011-12-29 08:30:43 +08:00
|
|
|
|
|
|
|
|
|
ZSH_THEME_PROMPT_RETURNCODE_PREFIX="%{$fg_bold[red]%}"
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_PREFIX=" $fg[white]‹ %{$fg_bold[yellow]%}"
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg_bold[magenta]%}↑"
|
2018-07-02 02:41:52 +08:00
|
|
|
|
ZSH_THEME_GIT_PROMPT_BEHIND="%{$fg_bold[green]%}↓"
|
2011-12-29 08:30:43 +08:00
|
|
|
|
ZSH_THEME_GIT_PROMPT_STAGED="%{$fg_bold[green]%}●"
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg_bold[red]%}●"
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[white]%}●"
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg_bold[red]%}✕"
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_SUFFIX=" $fg_bold[white]›%{$reset_color%}"
|