Skip to content

Expose current checked out tag #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
delthas opened this issue Jan 28, 2025 · 2 comments
Open

Expose current checked out tag #5

delthas opened this issue Jan 28, 2025 · 2 comments

Comments

@delthas
Copy link

delthas commented Jan 28, 2025

Is your feature request related to a problem? Please describe.

I often check out different tags in my projects to deploy them with different versions for testing. When I have a tag checked out, I'd really like to see the tag name in my prompt instead of a commit hash (that I never remember).

Describe the solution you'd like

I'd like git-info to expose the tag name of the current checked out tag (if a tag is checked out, so when in checked out HEAD state, but specifically when HEAD is pointing to a tag).

Describe alternatives you've considered

I suppose I could somehow do that manually by adding some script in my prompt to call git and check every time whether I have a tag checked out and append that to my prompt, but it's hacky and I think it could be useful to have that in git-info for other users.

Additional context

No response

@ericbn
Copy link
Member

ericbn commented Jan 29, 2025

Hi @delthas. I agree this is a very good one to have. Looks like git tag --points-at is the preferred way to do this. What should be the expected behavior when there is more than one tag? Show only the first?

@ericbn
Copy link
Member

ericbn commented Jan 29, 2025

Also, there's the position context which will give you the name of the tag that comes after or is at the current commit, when you're in detached HEAD mode.

For example, to see this in the asciiship prompt, do the following changes (replacing commit/%c by position/%p):

@@ -34,7 +34,7 @@ fi
 typeset -gA git_info
 if (( ${+functions[git-info]} )); then
   zstyle ':zim:git-info:branch' format '%b'
-  zstyle ':zim:git-info:commit' format 'HEAD %F{green}(%c)'
+  zstyle ':zim:git-info:position' format 'HEAD %F{green}(%p)'
   zstyle ':zim:git-info:action' format ' %F{yellow}(${(U):-%s})'
   zstyle ':zim:git-info:stashed' format '\\\$'
   zstyle ':zim:git-info:unindexed' format '!'
@@ -43,7 +43,7 @@ if (( ${+functions[git-info]} )); then
   zstyle ':zim:git-info:behind' format '<'
   zstyle ':zim:git-info:keys' format \
       'status' '%S%I%i%A%B' \
-      'prompt' ' on %%B%F{magenta}%b%c%s${(e)git_info[status]:+" %F{red}[${(e)git_info[status]}]"}%f%%b'
+      'prompt' ' on %%B%F{magenta}%b%p%s${(e)git_info[status]:+" %F{red}[${(e)git_info[status]}]"}%f%%b'
   add-zsh-hook precmd git-info
 fi

Example:

macbookpro in /path/to/zimfw on master
% Gyd v1.17.0
HEAD is now at d74be7c v1.17.0

macbookpro in /path/to/zimfw on HEAD (v1.17.0)
%

EDIT: Normally you'd want to fallback to showing the current commit short hash in case no tag was found, using $(coalesce %p %c) instead of just %p:

@@ -34,7 +34,7 @@ fi
 typeset -gA git_info
 if (( ${+functions[git-info]} )); then
   zstyle ':zim:git-info:branch' format '%b'
+  zstyle ':zim:git-info:position' format 'HEAD %F{green}(%p)'
   zstyle ':zim:git-info:commit' format 'HEAD %F{green}(%c)'
   zstyle ':zim:git-info:action' format ' %F{yellow}(${(U):-%s})'
   zstyle ':zim:git-info:stashed' format '\\\$'
   zstyle ':zim:git-info:unindexed' format '!'
@@ -43,7 +43,7 @@ if (( ${+functions[git-info]} )); then
   zstyle ':zim:git-info:behind' format '<'
   zstyle ':zim:git-info:keys' format \
       'status' '%S%I%i%A%B' \
-      'prompt' ' on %%B%F{magenta}%b%c%s${(e)git_info[status]:+" %F{red}[${(e)git_info[status]}]"}%f%%b'
+      'prompt' ' on %%B%F{magenta}%b$(coalesce %p %c)%s${(e)git_info[status]:+" %F{red}[${(e)git_info[status]}]"}%f%%b'
   add-zsh-hook precmd git-info
 fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants