feat: add git sync info
This commit is contained in:
parent
91c8a55eb2
commit
f829660dd2
1 changed files with 9 additions and 22 deletions
31
prompt.zsh
31
prompt.zsh
|
@ -12,7 +12,7 @@ function git_prompt_info() {
|
|||
if ! __git_prompt_git rev-parse --git-dir &> /dev/null ; then
|
||||
return 0
|
||||
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() {
|
||||
|
@ -26,29 +26,16 @@ function git_current_branch() {
|
|||
echo ${ref#refs/heads/}
|
||||
}
|
||||
|
||||
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
|
||||
function git_sync_info() {
|
||||
local behind
|
||||
local ahead
|
||||
if git rev-parse --is-inside-work-tree &>/dev/null; then
|
||||
local branch=$(git_current_branch)
|
||||
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|')"
|
||||
if [[ "${ahead}" != "0" ]] || [[ "${behind}" != "0" ]]; then
|
||||
echo "%{$fg[yellow]%}%1{±%}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function prompt_python_venv() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue