We're formatting our branch name like feature/HD-1234_tiny_description
where "1234" refers to a Jira ticket number. I'd like to only display this number in vim-airline (along with vim-fugitive)
According to the docs:
vim-airline will display the branch-indicator together with the branch name in the statusline, if one of the following plugins is installed:
- fugitive.vim https://github.com/tpope/vim-fugitive
- ...
if a string is provided, it should be the name of a function that takes a string and returns the desired value
let g:airline#extensions#branch#format = 'CustomBranchName' function! CustomBranchName(name) return '[' . a:name . ']' endfunctionlet
So I'm naively tried
let g:airline#extensions#branch#format = 'JiraTicketNumber'
function! JiraTicketNumber(name)
return matchstr(name, '/feature\/hd[-_]{1}(\d{4})/i')[1]
endfunction
which returns an error undefined variable : name
(roughly translated).
Could anyone give me an helping hand ?
Ideally I'd like to return the ticket number only if the branch name starts by "feature" (so fix/...
and chore/...
would be simply truncated via let g:airline#extensions#branch#format = 1
)
Should this work ?
let g:airline#extensions#branch#format = 'JiraTicketNumber'
function! JiraTicketNumber(name)
if name =~ 'feature'
return matchstr(name, '/feature\/hd[-_]{1}(\d{4})/i')[1]
else
return name
endif
endfunction