git: enable gitrepo path style, displaying repo:/path/ instead

fixes:  #2505
closes: #2507

Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Christian Brabandt
2026-04-12 08:04:38 +00:00
parent c52bb3dd32
commit 081f8ac918
3 changed files with 29 additions and 0 deletions
+2
View File
@@ -199,6 +199,8 @@ function! airline#init#bootstrap()
\ })
if get(g:, 'airline_section_c_only_filename',0)
call airline#parts#define_raw('file', '%t%m')
elseif get(g:, 'airline_stl_path_style', 'default') ==# 'gitrepo'
call airline#parts#define_function('file', 'airline#parts#gitrepo')
else
call airline#parts#define_raw('file', airline#formatter#short_path#format('%f%m'))
endif
+21
View File
@@ -214,3 +214,24 @@ function! airline#parts#executable()
return ''
endif
endfunction
function! airline#parts#gitrepo() abort
if !exists('*FugitiveFind')
return expand('%:p')
endif
let toplevel = FugitiveFind(':/', bufnr(''))
if empty(toplevel)
return expand('%:p')
endif
" Remove trailing separator
let toplevel = substitute(toplevel, '[/\\]$', '', '')
let reponame = fnamemodify(toplevel, ':t')
let fullpath = resolve(expand('%:p'))
" Get file path relative to repo root
if fullpath[:len(toplevel)-1] ==# toplevel
let relpath = fullpath[len(toplevel)+1:]
else
let relpath = expand('%:t')
endif
return reponame .. ':' .. relpath .. (&modified ? '[+]' : '')
endfunction
+6
View File
@@ -306,6 +306,12 @@ values):
* Display a short path in statusline: >
let g:airline_stl_path_style = 'short'
>
* Display the file path relative to the git repository toplevel directory: >
let g:airline_stl_path_style = 'gitrepo'
<
This shows the path as `reponame:path/to/file` instead of the full path.
Requires fugitive plugin. Falls back to the full path for non-git files.
* Display a only file name in statusline: >
let g:airline_section_c_only_filename = 1
>