feat: add git sync info

This commit is contained in:
Adrien Waksberg 2025-05-02 11:15:21 +02:00
parent 91c8a55eb2
commit f829660dd2

View file

@ -12,7 +12,7 @@ function git_prompt_info() {
if ! __git_prompt_git rev-parse --git-dir &> /dev/null ; then if ! __git_prompt_git rev-parse --git-dir &> /dev/null ; then
return 0 return 0
fi fi
echo "%{$reset_color%}\ue725 on %{$fg[green]%}$(git_current_branch)$(parse_git_dirty)%{$reset_color%} " echo "%{$reset_color%}\ue725 on %{$fg[green]%}$(git_current_branch)$(git_sync_info)%{$reset_color%} "
} }
function git_current_branch() { function git_current_branch() {
@ -26,28 +26,15 @@ function git_current_branch() {
echo ${ref#refs/heads/} echo ${ref#refs/heads/}
} }
function parse_git_dirty() { function git_sync_info() {
local STATUS local behind
local -a FLAGS local ahead
FLAGS=('--porcelain') if git rev-parse --is-inside-work-tree &>/dev/null; then
if [[ "$(__git_prompt_git config --get oh-my-zsh.hide-dirty)" != "1" ]]; then local branch=$(git_current_branch)
if [[ "${DISABLE_UNTRACKED_FILES_DIRTY:-}" == "true" ]]; then IFS=: read behind ahead <<<"$(git rev-list --left-right --count ${branch}...origin/${branch} 2>/dev/null | sed 's|^\([0-9]\+\)\s\+\([0-9]\+\)|\1:\2|')"
FLAGS+='--untracked-files=no' if [[ "${ahead}" != "0" ]] || [[ "${behind}" != "0" ]]; then
echo "%{$fg[yellow]%}%1{±%}"
fi 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 "%{$fg[yellow]%}%1{±%}"
fi fi
} }