diff options
| author | Alvaro Sevilla <alvaro@chainalysis.com> | 2021-07-05 04:39:34 +0100 | 
|---|---|---|
| committer | Alvaro Sevilla <alvaro@chainalysis.com> | 2021-07-05 11:10:31 +0100 | 
| commit | 3f16ab28d6bd9ed7bb23d35118fcaebce4ad2b0f (patch) | |
| tree | fc2f59b4c94a8335c52530248ef10b59b6b2d8b9 | |
| parent | c7ae93d6eb6aca8099aead0b54193b70faca7e66 (diff) | |
| download | minitab.nvim-3f16ab28d6bd9ed7bb23d35118fcaebce4ad2b0f.tar.xz minitab.nvim-3f16ab28d6bd9ed7bb23d35118fcaebce4ad2b0f.zip | |
Implement luatab
| -rw-r--r-- | lua/luatab/init.lua | 91 | 
1 files changed, 91 insertions, 0 deletions
| diff --git a/lua/luatab/init.lua b/lua/luatab/init.lua new file mode 100644 index 0000000..333ea2e --- /dev/null +++ b/lua/luatab/init.lua @@ -0,0 +1,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 | 
