aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--functions/vcs.zsh24
-rwxr-xr-xpowerlevel9k.zsh-theme15
2 files changed, 28 insertions, 11 deletions
diff --git a/functions/vcs.zsh b/functions/vcs.zsh
index 9d3883ca..15f0177e 100644
--- a/functions/vcs.zsh
+++ b/functions/vcs.zsh
@@ -61,10 +61,26 @@ function +vi-git-remotebranch() {
}
function +vi-git-tagname() {
- local tag
-
- tag=$(git describe --tags --exact-match HEAD 2>/dev/null)
- [[ -n "${tag}" ]] && hook_com[branch]="$(print_icon 'VCS_TAG_ICON')${tag}"
+ # 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
+ fi
}
# Show count of stashed changes
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 8a0c43fb..8bba6632 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -815,7 +815,14 @@ prompt_todo() {
# VCS segment: shows the state of your repository, if you are in a folder under
# version control
set_default POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND "red"
+# Default: Just display the first 8 characters of our changeset-ID.
+set_default POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH "8"
prompt_vcs() {
+ if [[ -n "$POWERLEVEL9K_CHANGESET_HASH_LENGTH" ]]; then
+ POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH="$POWERLEVEL9K_CHANGESET_HASH_LENGTH"
+ fi
+
+ # Load VCS_INFO
autoload -Uz vcs_info
VCS_WORKDIR_DIRTY=false
@@ -832,13 +839,7 @@ prompt_vcs() {
VCS_CHANGESET_PREFIX=''
if [[ "$POWERLEVEL9K_SHOW_CHANGESET" == true ]]; then
- # Default: Just display the first 12 characters of our changeset-ID.
- local VCS_CHANGESET_HASH_LENGTH=12
- if [[ -n "$POWERLEVEL9K_CHANGESET_HASH_LENGTH" ]]; then
- VCS_CHANGESET_HASH_LENGTH="$POWERLEVEL9K_CHANGESET_HASH_LENGTH"
- fi
-
- VCS_CHANGESET_PREFIX="$(print_icon 'VCS_COMMIT_ICON')%0.$VCS_CHANGESET_HASH_LENGTH""i "
+ VCS_CHANGESET_PREFIX="$(print_icon 'VCS_COMMIT_ICON')%0.$POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH""i "
fi
zstyle ':vcs_info:*' enable git hg