diff options
Diffstat (limited to '')
-rw-r--r-- | lua/tar.lua | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/lua/tar.lua b/lua/tar.lua new file mode 100644 index 0000000..cc0b732 --- /dev/null +++ b/lua/tar.lua @@ -0,0 +1,87 @@ +local M = {} +local C = {} -- config table + +function M.setup(opts) + opts = opts or {} + + if opts.seperator then + if type(opts.seperator) == "string" then + C.seperatorstr = opts.seperator + elseif type(opts.seperator) == "function" then + C.seperator = opts.seperator + end + else + C.separator = M.separator + C.seperatorstr = "|" + end + + if opts.title then + if type(opts.title) == "function" then + C.title = opts.title + end + else + C.title = M.title + end + + if opts.sign then + if type(opts.sign) == "function" then + C.sign = opts.sign + end + else + C.sign = M.sign + end + + C.noname = opts.noname or "[No Name]" + C.closeicon = opts.closeicon or "[x]" + + vim.opt.tabline = "%!v:lua.require\'tar\'.tabline()" +end + +function M.title(bufnr) + local fn = vim.fn.bufname(bufnr) + + if fn == '' then + return C.noname + else + return vim.fn.pathshorten(vim.fn.fnamemodify(fn, ':p:~:t')) + end +end + +function M.sign(bufnr) + if vim.fn.getbufvar(bufnr, '&modified') == 1 then + return '[+]' + elseif vim.fn.getbufvar(bufnr, '&readonly') == 1 then + return '[=]' + else + return + end +end + +function M.separator(index) + return (index < vim.fn.tabpagenr('$') and '%#TabLine#'..C.seperatorstr or '') +end + +function M.tab(index) + local sel = vim.fn.tabpagenr() == index + local buflist = vim.fn.tabpagebuflist(index) + local winnr = vim.fn.tabpagewinnr(index) + local bufnr = buflist[winnr] + local hl = (sel and '%#TabLineSel#' or '%#TabLine#') + + return hl..'%'..index..'T '..C.title(bufnr)..' '..(C.sign(bufnr) + and M.sign(bufnr)..' ' or '')..C.separator(index) +end + +function M.tabline() + local line = '' + for i = 1, vim.fn.tabpagenr('$') do + line = line..M.tab(i) + end + line = line..'%#TabLineFill#%=' + if vim.fn.tabpagenr('$') > 1 then + line = line..'%#TabLine#%999X'..C.closeicon + end + return line +end + +return M |