mirror of
https://github.com/vim-airline/vim-airline.git
synced 2026-04-27 09:01:24 +08:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user