1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
local function tabName(bufnr)
local file = vim.fn.bufname(bufnr)
local buftype = vim.fn.getbufvar(bufnr, '&buftype')
local filetype = vim.fn.getbufvar(bufnr, '&filetype')
if file == '' then
return '[No Name]'
elseif buftype == 'help' then
return 'help:' .. vim.fn.fnamemodify(file, ':t:r')
elseif buftype == 'quickfix' then
return 'quickfix'
elseif filetype == 'TelescopePrompt' then
return 'Telescope'
elseif file:sub(file:len()-2, file:len()) == 'FZF' then
return 'FZF'
elseif buftype == 'terminal' then
return 'zsh'
end
return vim.fn.pathshorten(vim.fn.fnamemodify(file, ':p:~:t'))
end
local function tabModified(bufnr)
return vim.fn.getbufvar(bufnr, '&modified') == 1 and '[+] ' or ''
end
local function tabWindowCount(current)
local nwins = vim.fn.tabpagewinnr(current, '$')
return nwins > 1 and '(' .. nwins .. ') ' or ''
end
local function tabDevicon(bufnr, isSelected)
local dev, devhl
local file = vim.fn.bufname(bufnr)
local buftype = vim.fn.getbufvar(bufnr, '&buftype')
local filetype = vim.fn.getbufvar(bufnr, '&filetype')
if buftype == 'terminal' then
dev, devhl = require'nvim-web-devicons'.get_icon('zsh')
elseif filetype == 'fugitive' then
dev, devhl = require'nvim-web-devicons'.get_icon('git')
elseif filetype == 'vimwiki' then
dev, devhl = require'nvim-web-devicons'.get_icon('markdown')
else
dev, devhl = require'nvim-web-devicons'.get_icon(file, vim.fn.getbufvar(bufnr, '&filetype'))
end
if dev then
return (isSelected and '%#'..devhl..'#' or '') .. dev .. (isSelected and '%#TabLineSel#' or '')
end
return ''
end
local function tabSeparator(current)
return ' ' .. (current < vim.fn.tabpagenr('$') and '%#TabLine#|' or '')
end
local function formatTab(current)
local t = vim.fn.tabpagenr()
local isSelected = vim.fn.tabpagenr() == current
local buflist = vim.fn.tabpagebuflist(current)
local winnr = vim.fn.tabpagewinnr(current)
local bufnr = buflist[winnr]
local file = vim.fn.bufname(bufnr)
local hl = (isSelected and '%#TabLineSel#' or '%#TabLine#')
return hl .. ' ' ..
tabWindowCount(current) ..
tabName(bufnr) .. ' ' ..
tabModified(bufnr) ..
tabDevicon(bufnr, isSelected) ..
tabSeparator(current)
end
local function tabline()
local i = 1
local line = ''
while i <= vim.fn.tabpagenr('$') do
line = line .. formatTab(i)
i = i + 1
end
return line .. '%T%#TabLineFill#%='
end
local M = {
tabline = tabline,
formatTab = formatTab,
tabSeparator = tabSeparator,
tabWindowCount = tabWindowCount,
tabName = tabName,
tabModified = tabModified,
tabDevicon = tabDevicon,
}
return M
|