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:
parent
8f2fae5a38
commit
264a10fb0d
1 changed files with 66 additions and 36 deletions
|
@ -1571,6 +1571,13 @@ typeset -fH _p9k_vcs_render() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ $VCS_STATUS_RESULT == ok-* ]] || return 1
|
[[ $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=(
|
local -a cache_key=(
|
||||||
"$VCS_STATUS_LOCAL_BRANCH"
|
"$VCS_STATUS_LOCAL_BRANCH"
|
||||||
"$VCS_STATUS_REMOTE_BRANCH"
|
"$VCS_STATUS_REMOTE_BRANCH"
|
||||||
|
@ -1582,9 +1589,17 @@ typeset -fH _p9k_vcs_render() {
|
||||||
"$VCS_STATUS_COMMITS_AHEAD"
|
"$VCS_STATUS_COMMITS_AHEAD"
|
||||||
"$VCS_STATUS_COMMITS_BEHIND"
|
"$VCS_STATUS_COMMITS_BEHIND"
|
||||||
"$VCS_STATUS_STASHES"
|
"$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
|
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
|
if [[ $VCS_STATUS_HAS_STAGED != 0 || $VCS_STATUS_HAS_UNSTAGED != 0 ]]; then
|
||||||
state='modified'
|
state='modified'
|
||||||
elif [[ $VCS_STATUS_HAS_UNTRACKED != 0 ]]; then
|
elif [[ $VCS_STATUS_HAS_UNTRACKED != 0 ]]; then
|
||||||
|
@ -1593,7 +1608,8 @@ typeset -fH _p9k_vcs_render() {
|
||||||
state='clean'
|
state='clean'
|
||||||
fi
|
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
|
if [[ "$VCS_STATUS_REMOTE_URL" == *github* ]] then
|
||||||
_p9k_get_icon VCS_GIT_GITHUB_ICON
|
_p9k_get_icon VCS_GIT_GITHUB_ICON
|
||||||
vcs_prompt+=$_P9K_RETVAL
|
vcs_prompt+=$_P9K_RETVAL
|
||||||
|
@ -1610,44 +1626,58 @@ typeset -fH _p9k_vcs_render() {
|
||||||
_p9k_get_icon VCS_GIT_ICON
|
_p9k_get_icon VCS_GIT_ICON
|
||||||
vcs_prompt+=$_P9K_RETVAL
|
vcs_prompt+=$_P9K_RETVAL
|
||||||
fi
|
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
|
_p9k_get_icon VCS_BRANCH_ICON
|
||||||
vcs_prompt+="$_P9K_RETVAL$VCS_STATUS_LOCAL_BRANCH"
|
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
|
if [[ -n $VCS_STATUS_ACTION ]]; then
|
||||||
vcs_prompt+=" %F{${POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND}}| $VCS_STATUS_ACTION%f"
|
vcs_prompt+="%F{${POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND}}| $VCS_STATUS_ACTION%f"
|
||||||
else
|
else
|
||||||
if [[ -n $VCS_STATUS_REMOTE_BRANCH &&
|
if [[ -n $VCS_STATUS_REMOTE_BRANCH &&
|
||||||
$VCS_STATUS_LOCAL_BRANCH != $VCS_STATUS_REMOTE_BRANCH ]]; then
|
$VCS_STATUS_LOCAL_BRANCH != $VCS_STATUS_REMOTE_BRANCH ]]; then
|
||||||
_p9k_get_icon VCS_REMOTE_BRANCH_ICON
|
_p9k_get_icon VCS_REMOTE_BRANCH_ICON
|
||||||
vcs_prompt+=" $_P9K_RETVAL$VCS_STATUS_REMOTE_BRANCH"
|
vcs_prompt+="$_P9K_RETVAL$VCS_STATUS_REMOTE_BRANCH "
|
||||||
fi
|
fi
|
||||||
if [[ $VCS_STATUS_HAS_STAGED == 1 ]]; then
|
if [[ $VCS_STATUS_HAS_STAGED == 1 ]]; then
|
||||||
_p9k_get_icon VCS_STAGED_ICON
|
_p9k_get_icon VCS_STAGED_ICON
|
||||||
vcs_prompt+=" $_P9K_RETVAL"
|
vcs_prompt+="$_P9K_RETVAL "
|
||||||
fi
|
fi
|
||||||
if [[ $VCS_STATUS_HAS_UNSTAGED == 1 ]]; then
|
if [[ $VCS_STATUS_HAS_UNSTAGED == 1 ]]; then
|
||||||
_p9k_get_icon VCS_UNSTAGED_ICON
|
_p9k_get_icon VCS_UNSTAGED_ICON
|
||||||
vcs_prompt+=" $_P9K_RETVAL"
|
vcs_prompt+="$_P9K_RETVAL "
|
||||||
fi
|
fi
|
||||||
if [[ $VCS_STATUS_HAS_UNTRACKED == 1 ]]; then
|
if [[ $VCS_STATUS_HAS_UNTRACKED == 1 ]]; then
|
||||||
_p9k_get_icon VCS_UNTRACKED_ICON
|
_p9k_get_icon VCS_UNTRACKED_ICON
|
||||||
vcs_prompt+=" $_P9K_RETVAL"
|
vcs_prompt+="$_P9K_RETVAL "
|
||||||
fi
|
fi
|
||||||
if [[ $VCS_STATUS_COMMITS_AHEAD -gt 0 ]]; then
|
if [[ $VCS_STATUS_COMMITS_AHEAD -gt 0 ]]; then
|
||||||
_p9k_get_icon VCS_OUTGOING_CHANGES_ICON
|
_p9k_get_icon VCS_OUTGOING_CHANGES_ICON
|
||||||
vcs_prompt+=" $_P9K_RETVAL$VCS_STATUS_COMMITS_AHEAD"
|
vcs_prompt+="$_P9K_RETVAL$VCS_STATUS_COMMITS_AHEAD "
|
||||||
fi
|
fi
|
||||||
if [[ $VCS_STATUS_COMMITS_BEHIND -gt 0 ]]; then
|
if [[ $VCS_STATUS_COMMITS_BEHIND -gt 0 ]]; then
|
||||||
_p9k_get_icon VCS_INCOMING_CHANGES_ICON
|
_p9k_get_icon VCS_INCOMING_CHANGES_ICON
|
||||||
vcs_prompt+=" $_P9K_RETVAL$VCS_STATUS_COMMITS_BEHIND"
|
vcs_prompt+="$_P9K_RETVAL$VCS_STATUS_COMMITS_BEHIND "
|
||||||
fi
|
fi
|
||||||
if [[ $VCS_STATUS_STASHES -gt 0 ]]; then
|
if [[ $VCS_STATUS_STASHES -gt 0 ]]; then
|
||||||
_p9k_get_icon VCS_STASH_ICON
|
_p9k_get_icon VCS_STASH_ICON
|
||||||
vcs_prompt+=" $_P9K_RETVAL$VCS_STATUS_STASHES"
|
vcs_prompt+="$_P9K_RETVAL$VCS_STATUS_STASHES "
|
||||||
fi
|
fi
|
||||||
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
|
fi
|
||||||
|
|
||||||
_P9K_LAST_GIT_PROMPT[$VCS_STATUS_WORKDIR]="${_P9K_CACHE_VAL[3]}"
|
_P9K_LAST_GIT_PROMPT[$VCS_STATUS_WORKDIR]="${_P9K_CACHE_VAL[3]}"
|
||||||
|
@ -1782,7 +1812,7 @@ prompt_vi_mode() {
|
||||||
# https://virtualenv.pypa.io/en/latest/
|
# https://virtualenv.pypa.io/en/latest/
|
||||||
prompt_virtualenv() {
|
prompt_virtualenv() {
|
||||||
if [[ -n "$VIRTUAL_ENV" ]]; then
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue