diff options
Diffstat (limited to 'functions/vcs.zsh')
-rwxr-xr-x | functions/vcs.zsh | 74 |
1 files changed, 36 insertions, 38 deletions
diff --git a/functions/vcs.zsh b/functions/vcs.zsh index d89525fd..7c431067 100755 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -1,12 +1,3 @@ -# vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 -################################################################ -# vcs -# This file holds supplemental VCS functions -# for the powerlevel9k-ZSH-theme -# https://github.com/bhilburn/powerlevel9k -################################################################ - -set_default POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY false function +vi-git-untracked() { [[ -z "${vcs_comm[gitdir]}" || "${vcs_comm[gitdir]}" == "." ]] && return @@ -17,7 +8,7 @@ function +vi-git-untracked() { local untrackedFiles=$(command git ls-files --others --exclude-standard "${repoTopLevel}" 2> /dev/null) - if [[ -z $untrackedFiles && "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" ]]; then + if [[ -z $untrackedFiles && $_POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY == 1 ]]; then untrackedFiles+=$(command git submodule foreach --quiet --recursive 'command git ls-files --others --exclude-standard' 2> /dev/null) fi @@ -51,20 +42,24 @@ function +vi-git-remotebranch() { # Are we on a remote-tracking branch? remote=${$(command git rev-parse --verify HEAD@{upstream} --symbolic-full-name 2>/dev/null)/refs\/(remotes|heads)\/} - if [[ -n "$POWERLEVEL9K_VCS_SHORTEN_LENGTH" ]] && [[ -n "$POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH" ]]; then - if [ ${#hook_com[branch]} -gt ${POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH} ] && [ ${#hook_com[branch]} -gt ${POWERLEVEL9K_VCS_SHORTEN_LENGTH} ]; then - case "$POWERLEVEL9K_VCS_SHORTEN_STRATEGY" in + if (( $+_POWERLEVEL9K_VCS_SHORTEN_LENGTH && $+_POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH )); then + if (( ${#hook_com[branch]} > _POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH && ${#hook_com[branch]} > _POWERLEVEL9K_VCS_SHORTEN_LENGTH )); then + case $_POWERLEVEL9K_VCS_SHORTEN_STRATEGY in truncate_middle) - hook_com[branch]="${branch_name:0:$POWERLEVEL9K_VCS_SHORTEN_LENGTH}${POWERLEVEL9K_VCS_SHORTEN_DELIMITER}${branch_name: -$POWERLEVEL9K_VCS_SHORTEN_LENGTH}" + hook_com[branch]="${branch_name:0:$_POWERLEVEL9K_VCS_SHORTEN_LENGTH}${_POWERLEVEL9K_VCS_SHORTEN_DELIMITER}${branch_name: -$_POWERLEVEL9K_VCS_SHORTEN_LENGTH}" ;; truncate_from_right) - hook_com[branch]="${branch_name:0:$POWERLEVEL9K_VCS_SHORTEN_LENGTH}${POWERLEVEL9K_VCS_SHORTEN_DELIMITER}" + hook_com[branch]="${branch_name:0:$_POWERLEVEL9K_VCS_SHORTEN_LENGTH}${_POWERLEVEL9K_VCS_SHORTEN_DELIMITER}" ;; esac fi fi - hook_com[branch]="$(print_icon 'VCS_BRANCH_ICON')${hook_com[branch]}" + if (( _POWERLEVEL9K_HIDE_BRANCH_ICON )); then + hook_com[branch]="${hook_com[branch]}" + else + hook_com[branch]="$(print_icon 'VCS_BRANCH_ICON')${hook_com[branch]}" + fi # Always show the remote #if [[ -n ${remote} ]] ; then # Only show the remote if it differs from the local @@ -73,30 +68,33 @@ function +vi-git-remotebranch() { fi } -set_default POWERLEVEL9K_VCS_HIDE_TAGS false function +vi-git-tagname() { - if [[ "$POWERLEVEL9K_VCS_HIDE_TAGS" == "false" ]]; then - # If we are on a tag, append the tagname to the current branch string. - local tag - tag=$(command git describe --tags --exact-match HEAD 2>/dev/null) - - if [[ -n "${tag}" ]] ; then - # There is a tag that points to our current commit. Need to determine if we - # are also on a branch, or are in a DETACHED_HEAD state. - if [[ -z $(command git symbolic-ref HEAD 2>/dev/null) ]]; then - # DETACHED_HEAD state. We want to append the tag name to the commit hash - # and print it. Unfortunately, `vcs_info` blows away the hash when a tag - # exists, so we have to manually retrieve it and clobber the branch - # string. - local revision - revision=$(command git rev-list -n 1 --abbrev-commit --abbrev=${POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH} HEAD) + if (( !_POWERLEVEL9K_VCS_HIDE_TAGS )); then + # If we are on a tag, append the tagname to the current branch string. + local tag + tag=$(command git describe --tags --exact-match HEAD 2>/dev/null) + + if [[ -n "${tag}" ]] ; then + # There is a tag that points to our current commit. Need to determine if we + # are also on a branch, or are in a DETACHED_HEAD state. + if [[ -z $(command git symbolic-ref HEAD 2>/dev/null) ]]; then + # DETACHED_HEAD state. We want to append the tag name to the commit hash + # and print it. Unfortunately, `vcs_info` blows away the hash when a tag + # exists, so we have to manually retrieve it and clobber the branch + # string. + local revision + revision=$(command git rev-list -n 1 --abbrev-commit --abbrev=${_POWERLEVEL9K_CHANGESET_HASH_LENGTH} HEAD) + if (( _POWERLEVEL9K_HIDE_BRANCH_ICON )); then + hook_com[branch]="${revision} $(print_icon 'VCS_TAG_ICON')${tag}" + else hook_com[branch]="$(print_icon 'VCS_BRANCH_ICON')${revision} $(print_icon 'VCS_TAG_ICON')${tag}" - else - # We are on both a tag and a branch; print both by appending the tag name. - hook_com[branch]+=" $(print_icon 'VCS_TAG_ICON')${tag}" - fi - fi - fi + fi + else + # We are on both a tag and a branch; print both by appending the tag name. + hook_com[branch]+=" $(print_icon 'VCS_TAG_ICON')${tag}" + fi + fi + fi } # Show count of stashed changes |