From 33663d7df2d2f47b63bc4849c3a1c051f609d255 Mon Sep 17 00:00:00 2001 From: Cimbali Date: Wed, 22 Nov 2017 22:11:58 +0100 Subject: [PATCH] Show buffer name relative to git folder --- autoload/airline/extensions.vim | 6 ++++ autoload/airline/extensions/fugitiveline.vim | 37 ++++++++++++++++++++ doc/airline.txt | 7 ++++ 3 files changed, 50 insertions(+) create mode 100644 autoload/airline/extensions/fugitiveline.vim diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index 79f6bec..6de9c83 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -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') diff --git a/autoload/airline/extensions/fugitiveline.vim b/autoload/airline/extensions/fugitiveline.vim new file mode 100644 index 0000000..e2fcad7 --- /dev/null +++ b/autoload/airline/extensions/fugitiveline.vim @@ -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 + diff --git a/doc/airline.txt b/doc/airline.txt index ae43254..051b5d2 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -400,6 +400,13 @@ vim-bufferline * determine whether bufferline will overwrite customization variables > let g:airline#extensions#bufferline#overwrite_variables = 1 < +------------------------------------- *airline-fugitiveline* +This extension hides the fugitive://**// part of the buffer names, to only +show the file name as if it were in the current working tree. + +* enable/disable bufferline integration > + let g:airline#extensions#fugitiveline#enabled = 1 +< ------------------------------------- *airline-branch* vim-airline will display the branch-indicator together with the branch name in