diff --git a/plugins/git/functions/git-info b/plugins/git/functions/git-info index b5cfd33f..3b99bcd1 100644 --- a/plugins/git/functions/git-info +++ b/plugins/git/functions/git-info @@ -143,6 +143,7 @@ function git-info { local modified_format local modified_formatted local position + local position_cmd local position_format local position_formatted local prompt_format @@ -204,6 +205,20 @@ function git-info { # Gets the commit difference counts between local and remote. ahead_and_behind_cmd='git rev-list --count --left-right HEAD...@{upstream}' + # Use describe to get the current position + zstyle -s 'omz:plugin:git:prompt:position' style 'position_style' + case "$position_style" in + (contains) + position_cmd='git describe --contains --tags HEAD' + ;; + (references) + position_cmd='git describe --contains --all HEAD' + ;; + (tags) + position_cmd='git describe --tags HEAD' + ;; + esac + # Ignore submodule status. zstyle -b \ ':omz:plugin:git:prompt:ignore' submodule 'ignore_submodule' @@ -279,7 +294,7 @@ function git-info { fi else # Format position. - position="$(git describe --contains --all HEAD 2> /dev/null)" + position="$(${(z)position_cmd} 2> /dev/null)" if [[ -n "$position" ]]; then zstyle -s ':omz:plugin:git:prompt' position 'position_format' zformat -f position_formatted "$position_format" "p:$position" diff --git a/plugins/git/style.zsh b/plugins/git/style.zsh index d1196ef4..c5efed73 100644 --- a/plugins/git/style.zsh +++ b/plugins/git/style.zsh @@ -56,6 +56,9 @@ zstyle ':omz:plugin:git:prompt' prompt ' git:(%b %D)' # Right prompt. zstyle ':omz:plugin:git:prompt' rprompt '' +# Position style "contains", "references", "tags" +zstyle ':omz:plugin:git:prompt:position' style 'references' + # Ignore submodule. zstyle ':omz:plugin:git:prompt:ignore' submodule 'no'