implement gitstatusd support

This commit is contained in:
Markus Krause
2019-10-06 12:33:12 +02:00
committed by Noah Gorny
parent e0dba93561
commit 83fdc89ec1
4 changed files with 105 additions and 27 deletions

View File

@@ -34,6 +34,8 @@ SCM_GIT_SHOW_CURRENT_USER=${SCM_GIT_SHOW_CURRENT_USER:=false}
SCM_GIT_SHOW_MINIMAL_INFO=${SCM_GIT_SHOW_MINIMAL_INFO:=false}
SCM_GIT_SHOW_STASH_INFO=${SCM_GIT_SHOW_STASH_INFO:=true}
SCM_GIT_SHOW_COMMIT_COUNT=${SCM_GIT_SHOW_COMMIT_COUNT:=true}
SCM_GIT_USE_GITSTATUSD=${SCM_GIT_USE_GITSTATUSD:=false}
SCM_GIT_GITSTATUSD_LOC=${SCM_GIT_GITSTATUSD_LOC:="$HOME/gitstatus/gitstatus.plugin.sh"}
SCM_GIT='git'
SCM_GIT_CHAR='±'
@@ -191,6 +193,15 @@ function git_prompt_minimal_info {
}
function git_prompt_vars {
if ${SCM_GIT_USE_GITSTATUSD}; then # use faster gitstatusd
gitstatus_query # call gitstatusd
if [[ -z ${VCS_STATUS_WORKDIR} ]] ; then # this var is guaranteed to exist if query was successful
SCM_GIT_GITSTATUSD_RAN=false
else
SCM_GIT_GITSTATUSD_RAN=true # use this in githelpers and below to choose gitstatusd output
fi
fi
if _git-branch &> /dev/null; then
SCM_GIT_DETACHED="false"
SCM_BRANCH="${SCM_THEME_BRANCH_PREFIX}\$(_git-friendly-ref)$(_git-remote-info)"
@@ -206,7 +217,12 @@ function git_prompt_vars {
SCM_BRANCH="${detached_prefix}\$(_git-friendly-ref)"
fi
IFS=$'\t' read -r commits_behind commits_ahead <<< "$(_git-upstream-behind-ahead)"
if [[ "${SCM_GIT_GITSTATUSD_RAN}" == "true" ]]; then
commits_behind=${VCS_STATUS_COMMITS_BEHIND}
commits_ahead=${VCS_STATUS_COMMITS_AHEAD}
else
IFS=$'\t' read -r commits_behind commits_ahead <<< "$(_git-upstream-behind-ahead)"
fi
if [[ "${commits_ahead}" -gt 0 ]]; then
SCM_BRANCH+="${SCM_GIT_AHEAD_BEHIND_PREFIX_CHAR}${SCM_GIT_AHEAD_CHAR}"
[[ "${SCM_GIT_SHOW_COMMIT_COUNT}" = "true" ]] && SCM_BRANCH+="${commits_ahead}"
@@ -218,13 +234,23 @@ function git_prompt_vars {
if [[ "${SCM_GIT_SHOW_STASH_INFO}" = "true" ]]; then
local stash_count
stash_count="$(git stash list 2> /dev/null | wc -l | tr -d ' ')"
if [[ "${SCM_GIT_GITSTATUSD_RAN}" == "true" ]]; then
stash_count=${VCS_STATUS_STASHES}
else
stash_count="$(git stash list 2> /dev/null | wc -l | tr -d ' ')"
fi
[[ "${stash_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_STASH_CHAR_PREFIX}${stash_count}${SCM_GIT_STASH_CHAR_SUFFIX}"
fi
SCM_STATE=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN}
if ! _git-hide-status; then
IFS=$'\t' read -r untracked_count unstaged_count staged_count <<< "$(_git-status-counts)"
if [[ "${SCM_GIT_GITSTATUSD_RAN}" == "true" ]]; then
untracked_count=${VCS_STATUS_NUM_UNTRACKED}
unstaged_count=${VCS_STATUS_NUM_UNSTAGED}
staged_count=${VCS_STATUS_NUM_STAGED}
else
IFS=$'\t' read -r untracked_count unstaged_count staged_count <<< "$(_git-status-counts)"
fi
if [[ "${untracked_count}" -gt 0 || "${unstaged_count}" -gt 0 || "${staged_count}" -gt 0 ]]; then
SCM_DIRTY=1
if [[ "${SCM_GIT_SHOW_DETAILS}" = "true" ]]; then
@@ -236,12 +262,13 @@ function git_prompt_vars {
fi
fi
# no if for gitstatusd here, user extraction is not supported by it
[[ "${SCM_GIT_SHOW_CURRENT_USER}" == "true" ]] && SCM_BRANCH+="$(git_user_info)"
SCM_PREFIX=${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}
SCM_SUFFIX=${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}
SCM_CHANGE=$(_git-short-sha 2>/dev/null || echo "")
}
function p4_prompt_vars {