From 3291b4d476fdd43a2a111f811f99f1ee088843e4 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Tue, 12 Jul 2016 20:28:01 -0400 Subject: [PATCH] Merging ability to hide tags from VCS segment. --- README.md | 2 +- functions/vcs.zsh | 41 +++++++++++++++++++++-------------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 63908782..164b484f 100644 --- a/README.md +++ b/README.md @@ -348,7 +348,7 @@ customization is provided via: |`POWERLEVEL9K_SHOW_CHANGESET`|`false`|Set to `true` to display the hash / changeset in the segment.| |`POWERLEVEL9K_CHANGESET_HASH_LENGTH`|`12`|How many characters of the hash / changeset to display in the segment.| |`POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY`|`true`|Set to `false` to not reflect submodule status in the top-level repository prompt.| -|`POWERLEVEL9K_VCS_HIDE_TAGS`|unset|Set to `true` to stop tags being displayed in the segment.| +|`POWERLEVEL9K_VCS_HIDE_TAGS`|`false`|Set to `true` to stop tags being displayed in the segment.| ##### vcs symbols diff --git a/functions/vcs.zsh b/functions/vcs.zsh index b2d87d30..657a0f3f 100644 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -60,29 +60,30 @@ function +vi-git-remotebranch() { fi } +set_default POWERLEVEL9K_VCS_HIDE_TAGS false function +vi-git-tagname() { - if [[ -z "${POWERLEVE9K_VCS_HIDE_TAGS}" ]]; then - # If we are on a tag, append the tagname to the current branch string. - local tag - tag=$(git describe --tags --exact-match HEAD 2>/dev/null) + if [[ "$POWERLEVE9K_VCS_HIDE_TAGS" == "false" ]]; then + # If we are on a tag, append the tagname to the current branch string. + local tag + tag=$(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 $(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=$(git rev-list -n 1 --abbrev-commit --abbrev=${POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH} HEAD) - 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 + 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 $(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=$(git rev-list -n 1 --abbrev-commit --abbrev=${POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH} HEAD) + 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 } # Show count of stashed changes