2019-03-25 19:27:10 +08:00
|
|
|
" MIT License. Copyright (c) 2013-2019 Bailey Ling et al.
|
2013-12-23 13:41:24 +08:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
2016-09-24 08:16:30 +08:00
|
|
|
scriptencoding utf-8
|
|
|
|
|
2015-02-14 07:58:54 +08:00
|
|
|
function! airline#extensions#tabline#formatters#unique_tail#format(bufnr, buffers)
|
2013-12-23 13:41:24 +08:00
|
|
|
let duplicates = {}
|
|
|
|
let tails = {}
|
|
|
|
let map = {}
|
|
|
|
for nr in a:buffers
|
|
|
|
let name = bufname(nr)
|
|
|
|
if empty(name)
|
2019-10-25 23:20:34 +08:00
|
|
|
let map[nr] = airline#extensions#tabline#formatters#default#wrap_name(nr, '[No Name]')
|
2013-12-23 13:41:24 +08:00
|
|
|
else
|
2020-02-27 20:37:50 +08:00
|
|
|
if name =~ 'term://'
|
|
|
|
" Neovim Terminal
|
|
|
|
let tail = substitute(name, '\(term:\)//.*:\(.*\)', '\1 \2', '')
|
|
|
|
else
|
|
|
|
let tail = fnamemodify(name, ':s?/\+$??:t')
|
|
|
|
endif
|
2013-12-23 13:41:24 +08:00
|
|
|
if has_key(tails, tail)
|
|
|
|
let duplicates[nr] = nr
|
|
|
|
endif
|
|
|
|
let tails[tail] = 1
|
2015-02-14 07:58:54 +08:00
|
|
|
let map[nr] = airline#extensions#tabline#formatters#default#wrap_name(nr, tail)
|
2013-12-23 13:41:24 +08:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
2017-10-18 08:16:26 +08:00
|
|
|
let fmod = get(g:, 'airline#extensions#tabline#fnamemod', ':p:.')
|
2013-12-23 13:41:24 +08:00
|
|
|
for nr in values(duplicates)
|
2018-03-06 18:22:11 +08:00
|
|
|
let name = bufname(nr)
|
2017-10-18 08:16:26 +08:00
|
|
|
let fnamecollapse = get(g:, 'airline#extensions#tabline#fnamecollapse', 1)
|
|
|
|
if fnamecollapse
|
|
|
|
let map[nr] = airline#extensions#tabline#formatters#default#wrap_name(nr, substitute(fnamemodify(name, fmod), '\v\w\zs.{-}\ze(\\|/)', '', 'g'))
|
|
|
|
else
|
2018-03-06 18:22:11 +08:00
|
|
|
let map[nr] = airline#extensions#tabline#formatters#default#wrap_name(nr, fnamemodify(name, fmod))
|
2017-10-18 08:16:26 +08:00
|
|
|
endif
|
2013-12-23 13:41:24 +08:00
|
|
|
endfor
|
|
|
|
|
2015-02-27 12:08:59 +08:00
|
|
|
if has_key(map, a:bufnr)
|
|
|
|
return map[a:bufnr]
|
|
|
|
endif
|
|
|
|
|
|
|
|
" if we get here, the buffer list isn't in sync with the selected buffer yet, fall back to the default
|
|
|
|
return airline#extensions#tabline#formatters#default#format(a:bufnr, a:buffers)
|
2013-12-23 13:41:24 +08:00
|
|
|
endfunction
|