64 lines
2.2 KiB
Bash
64 lines
2.2 KiB
Bash
function __git_prompt_git() {
|
|
GIT_OPTIONAL_LOCKS=0 command git "$@"
|
|
}
|
|
|
|
function parse_git_dirty() {
|
|
local STATUS
|
|
local -a FLAGS
|
|
FLAGS=('--porcelain')
|
|
if [[ "$(__git_prompt_git config --get oh-my-zsh.hide-dirty)" != "1" ]]; then
|
|
if [[ "${DISABLE_UNTRACKED_FILES_DIRTY:-}" == "true" ]]; then
|
|
FLAGS+='--untracked-files=no'
|
|
fi
|
|
case "${GIT_STATUS_IGNORE_SUBMODULES:-}" in
|
|
git)
|
|
# let git decide (this respects per-repo config in .gitmodules)
|
|
;;
|
|
*)
|
|
# if unset: ignore dirty submodules
|
|
# other values are passed to --ignore-submodules
|
|
FLAGS+="--ignore-submodules=${GIT_STATUS_IGNORE_SUBMODULES:-dirty}"
|
|
;;
|
|
esac
|
|
STATUS=$(__git_prompt_git status ${FLAGS} 2> /dev/null | tail -n 1)
|
|
fi
|
|
if [[ -n $STATUS ]]; then
|
|
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
|
|
else
|
|
echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
|
|
fi
|
|
}
|
|
|
|
function git_prompt_info() {
|
|
# If we are on a folder not tracked by git, get out.
|
|
# Otherwise, check for hide-info at global and local repository level
|
|
if ! __git_prompt_git rev-parse --git-dir &> /dev/null \
|
|
|| [[ "$(__git_prompt_git config --get oh-my-zsh.hide-info 2>/dev/null)" == 1 ]]; then
|
|
return 0
|
|
fi
|
|
|
|
local ref
|
|
ref=$(__git_prompt_git symbolic-ref --short HEAD 2> /dev/null) \
|
|
|| ref=$(__git_prompt_git describe --tags --exact-match HEAD 2> /dev/null) \
|
|
|| ref=$(__git_prompt_git rev-parse --short HEAD 2> /dev/null) \
|
|
|| return 0
|
|
|
|
# Use global ZSH_THEME_GIT_SHOW_UPSTREAM=1 for including upstream remote info
|
|
local upstream
|
|
if (( ${+ZSH_THEME_GIT_SHOW_UPSTREAM} )); then
|
|
upstream=$(__git_prompt_git rev-parse --abbrev-ref --symbolic-full-name "@{upstream}" 2>/dev/null) \
|
|
&& upstream=" -> ${upstream}"
|
|
fi
|
|
|
|
echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${ref:gs/%/%%}${upstream:gs/%/%%}$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_SUFFIX}"
|
|
}
|
|
|
|
local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
|
|
local host_status="$USER@${:-%m}"
|
|
PROMPT='${ret_status}${host_status} %{$fg[cyan]%}%~%{$reset_color%} $(git_prompt_info)'
|
|
|
|
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}"
|
|
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
|
|
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗"
|
|
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"
|