mirror of
https://github.com/vim-airline/vim-airline.git
synced 2026-02-05 09:27:36 +08:00
Show buffer name relative to git folder
This commit is contained in:
@@ -229,6 +229,12 @@ function! airline#extensions#load()
|
||||
call add(loaded_ext, 'bufferline')
|
||||
endif
|
||||
|
||||
if get(g:, 'airline#extensions#fugitiveline#enabled', 1)
|
||||
\ && exists('*fugitive#head')
|
||||
call airline#extensions#fugitiveline#init(s:ext)
|
||||
call add(loaded_ext, 'fugitiveline')
|
||||
endif
|
||||
|
||||
if (get(g:, 'airline#extensions#virtualenv#enabled', 1) && (exists(':VirtualEnvList') || isdirectory($VIRTUAL_ENV)))
|
||||
call airline#extensions#virtualenv#init(s:ext)
|
||||
call add(loaded_ext, 'virtualenv')
|
||||
|
||||
37
autoload/airline/extensions/fugitiveline.vim
Normal file
37
autoload/airline/extensions/fugitiveline.vim
Normal file
@@ -0,0 +1,37 @@
|
||||
" MIT License. Copyright (c) 2017 Cimbali.
|
||||
" vim: et ts=2 sts=2 sw=2
|
||||
|
||||
scriptencoding utf-8
|
||||
|
||||
if !exists('*fugitive#head')
|
||||
finish
|
||||
endif
|
||||
|
||||
|
||||
if exists("+autochdir") && &autochdir == 1
|
||||
let s:fmod = ':p'
|
||||
else
|
||||
let s:fmod = ':.'
|
||||
endif
|
||||
|
||||
function! airline#extensions#fugitiveline#bufname()
|
||||
try
|
||||
let buffer = fugitive#buffer()
|
||||
if buffer.type('blob')
|
||||
return fnamemodify(buffer.repo().translate(buffer.path()), s:fmod)
|
||||
endif
|
||||
catch
|
||||
endtry
|
||||
|
||||
return fnamemodify(bufname('%'), s:fmod)
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#fugitiveline#init(ext)
|
||||
if exists("+autochdir") && &autochdir == 1
|
||||
" if 'acd' is set, vim-airline uses the path section, so we need to redefine this here as well
|
||||
call airline#parts#define_raw('path', '%<%{airline#extensions#fugitiveline#bufname()}%m')
|
||||
else
|
||||
call airline#parts#define_raw('file', '%<%{airline#extensions#fugitiveline#bufname()}%m')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user