1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-11-16 17:50:09 +00:00

support tags and revisions in gitstatus-powered vcs segment; respect vcs hooks

This commit is contained in:
romkatv 2019-03-14 20:43:33 +01:00
parent 8f2fae5a38
commit 264a10fb0d

View file

@ -1571,6 +1571,13 @@ typeset -fH _p9k_vcs_render() {
fi
[[ $VCS_STATUS_RESULT == ok-* ]] || return 1
(( ${POWERLEVEL9K_VCS_GIT_HOOKS[(I)git-untracked]} )) || VCS_STATUS_HAS_UNTRACKED=0
(( ${POWERLEVEL9K_VCS_GIT_HOOKS[(I)git-aheadbehind]} )) || VCS_STATUS_COMMITS_AHEAD=0 && VCS_STATUS_COMMITS_BEHIND=0
(( ${POWERLEVEL9K_VCS_GIT_HOOKS[(I)git-stash]} )) || VCS_STATUS_STASHES=0
(( ${POWERLEVEL9K_VCS_GIT_HOOKS[(I)git-remotebranch]} )) || VCS_STATUS_REMOTE_BRANCH=""
(( ${POWERLEVEL9K_VCS_GIT_HOOKS[(I)git-tagname]} )) || VCS_STATUS_TAG=""
local -a cache_key=(
"$VCS_STATUS_LOCAL_BRANCH"
"$VCS_STATUS_REMOTE_BRANCH"
@ -1582,9 +1589,17 @@ typeset -fH _p9k_vcs_render() {
"$VCS_STATUS_COMMITS_AHEAD"
"$VCS_STATUS_COMMITS_BEHIND"
"$VCS_STATUS_STASHES"
"$VCS_STATUS_TAG"
)
if [[ $POWERLEVEL9K_SHOW_CHANGESET == true || -z $VCS_STATUS_LOCAL_BRANCH ]]; then
cache_key+=$VCS_STATUS_COMMIT
fi
if ! _p9k_cache_get "${(@)cache_key}"; then
local state
local state=clean
local vcs_prompt
if (( ${POWERLEVEL9K_VCS_GIT_HOOKS[(I)vcs-detect-changes]} )); then
if [[ $VCS_STATUS_HAS_STAGED != 0 || $VCS_STATUS_HAS_UNSTAGED != 0 ]]; then
state='modified'
elif [[ $VCS_STATUS_HAS_UNTRACKED != 0 ]]; then
@ -1593,7 +1608,8 @@ typeset -fH _p9k_vcs_render() {
state='clean'
fi
local vcs_prompt
# It's weird that removing vcs-detect-changes from POWERLEVEL9K_VCS_GIT_HOOKS gets rid
# of the GIT icon. That's what vcs_info does, so we do the same in the name of compatiblity.
if [[ "$VCS_STATUS_REMOTE_URL" == *github* ]] then
_p9k_get_icon VCS_GIT_GITHUB_ICON
vcs_prompt+=$_P9K_RETVAL
@ -1610,9 +1626,23 @@ typeset -fH _p9k_vcs_render() {
_p9k_get_icon VCS_GIT_ICON
vcs_prompt+=$_P9K_RETVAL
fi
fi
if [[ $POWERLEVEL9K_SHOW_CHANGESET == true || -z $VCS_STATUS_LOCAL_BRANCH ]]; then
_p9k_get_icon VCS_COMMIT_ICON
vcs_prompt+="$_P9K_RETVAL${VCS_STATUS_COMMIT:0:$POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH} "
fi
if [[ -n $VCS_STATUS_LOCAL_BRANCH ]]; then
_p9k_get_icon VCS_BRANCH_ICON
vcs_prompt+="$_P9K_RETVAL$VCS_STATUS_LOCAL_BRANCH "
fi
if [[ $POWERLEVEL9K_VCS_HIDE_TAGS == false && -n $VCS_STATUS_TAG ]]; then
_p9k_get_icon VCS_TAG_ICON
vcs_prompt+="$_P9K_RETVAL$VCS_STATUS_TAG "
fi
if [[ -n $VCS_STATUS_ACTION ]]; then
vcs_prompt+="%F{${POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND}}| $VCS_STATUS_ACTION%f"
else
@ -1647,7 +1677,7 @@ typeset -fH _p9k_vcs_render() {
fi
fi
_p9k_cache_set "${1}_${(U)state}" "${vcs_states[$state]}" "$vcs_prompt"
_p9k_cache_set "${1}_${(U)state}" "${vcs_states[$state]}" "${vcs_prompt% }"
fi
_P9K_LAST_GIT_PROMPT[$VCS_STATUS_WORKDIR]="${_P9K_CACHE_VAL[3]}"
@ -1782,7 +1812,7 @@ prompt_vi_mode() {
# https://virtualenv.pypa.io/en/latest/
prompt_virtualenv() {
if [[ -n "$VIRTUAL_ENV" ]]; then
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "${virtualenv_path:t}" 'PYTHON_ICON'
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "${VIRTUAL_ENV:t}" 'PYTHON_ICON'
fi
}