forked from vim-airline/vim-airline
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add improved short path tabline formatter
- Loading branch information
Showing
3 changed files
with
44 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
autoload/airline/extensions/tabline/formatters/short_path_improved.vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
" MIT License. Copyright (c) 2013-2021 Bailey Ling et al. | ||
" vim: et ts=2 sts=2 sw=2 | ||
|
||
scriptencoding utf-8 | ||
|
||
function! airline#extensions#tabline#formatters#short_path_improved#format(bufnr, buffers) abort | ||
let name = bufname(a:bufnr) | ||
if empty(name) | ||
return airline#extensions#tabline#formatters#default#wrap_name(a:bufnr, '[No Name]') | ||
endif | ||
|
||
let tail = s:tail(a:bufnr) | ||
let tails = s:tails(a:bufnr, a:buffers) | ||
|
||
if has_key(tails, tail) | ||
" Use short path for duplicates | ||
return airline#extensions#tabline#formatters#short_path#format(a:bufnr, a:buffers) | ||
endif | ||
|
||
" Use tail for unique filenames | ||
return airline#extensions#tabline#formatters#default#wrap_name(a:bufnr, tail) | ||
endfunction | ||
|
||
function! s:tails(self, buffers) abort | ||
let tails = {} | ||
for nr in a:buffers | ||
if nr != a:self | ||
let tails[s:tail(nr)] = 1 | ||
endif | ||
endfor | ||
return tails | ||
endfunction | ||
|
||
function! s:tail(bufnr) abort | ||
return fnamemodify(bufname(a:bufnr), ':t') | ||
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters