1

I work on git tags on a daily basis & switch between 'em. I have my lightline configured where it does display git branch in status bar of lightline. But I am trying to display git tag as well. gitbranch component from lightline does display the commit id when I checkout / switch to a tag but those commit ids are pretty much unusable.

Here is my lightline block in neovim config:

let g:lightline = {
        \ 'colorscheme': 'powerline',
        \ 'active': {
        \   'left': [['statuslinetabs', 'lineinfo'], ['gitbranch',  'gittag', 'readonly', 'modified']],
        \   'right': [['mode'], ['paste'], ['absolutepath']],
        \ },
        \ 'inactive': {
        \   'left': [[], ['line', 'relativepath', 'readonly', 'modified']],
        \   'right': [[], [], ['gitbranch']],
        \ },
        \ 'component_expand': {
        \   'statuslinetabs': 'LightlineStatuslineTabs',
        \ },
        \ 'component_function': {
        \   'gitbranch': 'MyFugitiveHead'
        \ },
        \  'component': {
        \    'clock': '%{strftime("%a %d %b %I:%M%p")}'
        \  },
        \ }

In help of fugitive's AUTOCOMMANDS section it does say -

    AUTOCOMMANDS                                    fugitive-autocommands

A handful of User autocommands are provided to allow extending and
overriding Fugitive behaviors.  Example usage:

        autocmd User FugitiveBlob,FugitiveStageBlob call s:BlobOverrides()

                                                User_FugitiveTag
FugitiveTag             After loading a tag object.

But I am unable to figure how to utilize that as neither component or component_fuction.

Please advice!

Thanks.

  • Another way I thought of doing it - having the output of ":G describe --tags" added somehow to a lightline section - but not sure how that's possible either as it displays the command and doesn't process the command for an output before displaying. – user1365433 Jun 01 '23 at 01:22

2 Answers2

0

You have set gittag in the active list:

\ 'active': {
        \   'left': [['statuslinetabs', 'lineinfo'], ['gitbranch',  'gittag', 'readonly', 'modified']],
        \   'right': [['mode'], ['paste'], ['absolutepath']],
        \ },

Then you should add:

...
'component_function': {
        \   'gitbranch': 'MyFugitiveHead'
         \   'gittag': 'FugitiveTag'
        \ },
...
Rico
  • 141
  • 5
  • Thanks Rico. But it doesn't work that way in my configuration - it simply doesn't display anything. Did it work in yours? – user1365433 Jun 02 '23 at 05:52
  • I just realized you have `MyFugitiveHead` instead `FugitiveHead`. This might be the problem. Also check what happens when you type the command `:FugitiveTag`, whether it displays the tag or not. – Rico Jun 02 '23 at 15:04
  • Thanks for your response again Rico. MyFugitiveHead is a custom function as: function MyFugitiveHead() let head = FugitiveHead() if head != "" let head = "\uf126 " .. head endif return head endfunction So its not related. I am not able to get anything after typing :FugitiveTag command. – user1365433 Jun 05 '23 at 06:54
  • I see. It does not work because FugitiveTag is not a command but a kind of event. Try `:Git describe --tags --abbrev=0` instead of `FugitiveTag`. – Rico Jun 05 '23 at 07:41
0

Found a solution, not the vim-fugitive but native git way - via system calls. Just declared below as a component (not function) and since I work with multiple tags sometimes, used xargs to show all tags pointing to head. Includes non-git files scenario command output sending to /dev/null.

        \  'component': {
        \    'gittag': '%{substitute(system("git tag --points-at HEAD 2>/dev/null | xargs"), "\n", "|", "g")}',
        \  },