From 4e6ad07b4bd217e9fb44d99225b3467d5c5f33f1 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Thu, 28 Nov 2024 11:21:25 -0600 Subject: cleanup and fix a few bugs --- README.md | 9 ++---- lua/minitab/init.lua | 81 ++++++++++++++++++++-------------------------------- minitab | 3 -- 3 files changed, 33 insertions(+), 60 deletions(-) delete mode 100644 minitab diff --git a/README.md b/README.md index 36961d8..bf7d914 100644 --- a/README.md +++ b/README.md @@ -6,17 +6,12 @@ Fork of ## Features * Just a lua rewrite of the tabline render function * No weird mixing buffers and tabs stuff +* Size/position of tabs doesn't change ## Install Using [`lazy.nvim`](https://github.com/folke/lazy.nvim) ```lua -{ url = 'https://git.tjkeller.xyz/minitab.nvim', config = true } -``` - -## Usage -Add this to your init.lua: -```lua -require('minitab').setup{} +return { url = 'https://git.tjkeller.xyz/minitab.nvim', config = true } ``` ## Configuration diff --git a/lua/minitab/init.lua b/lua/minitab/init.lua index 1ef909c..22beb44 100644 --- a/lua/minitab/init.lua +++ b/lua/minitab/init.lua @@ -1,62 +1,43 @@ local M = { - moduleNames = { 'init.lua', '__init__.py', } + moduleNames = { "init.lua", "__init__.py" }, + separatorC = "|", + modifiedC = "+", } -M.fileTitle = function(file) - file = vim.fn.fnamemodify(file, ':p:~') +M.title = function(bufnr, isSelected) + local file = vim.fn.simplify(vim.fn.bufname(bufnr)) local tail = vim.fn.fnamemodify(file, ':t') - - if tail == '' then - return vim.fn.fnamemodify(file, ':p:~') -- netrw; e.g. ~/dir/ - elseif vim.tbl_contains(M.moduleNames, tail) then - return vim.fn.fnamemodify(vim.fn.fnamemodify(file, ':h'), ':t') .. '/' .. tail -- e.g. minitab/init.lua - else - return tail - end -end - -M.title = function(bufnr) - local file = vim.fn.bufname(bufnr) local buftype = vim.fn.getbufvar(bufnr, '&buftype') local filetype = vim.fn.getbufvar(bufnr, '&filetype') - if buftype == 'help' then - return 'help:' .. vim.fn.fnamemodify(file, ':t:r') - elseif buftype == 'quickfix' then - return 'quickfix' - elseif filetype == 'TelescopePrompt' then - return 'Telescope' - elseif filetype == 'git' then - return 'Git' - elseif filetype == 'fugitive' then - return 'Fugitive' - elseif filetype == 'NvimTree' then - return 'NvimTree' - elseif filetype == 'oil' then - return 'Oil' - elseif file:sub(file:len()-2, file:len()) == 'FZF' then - return 'FZF' - elseif buftype == 'terminal' then - local _, mtch = string.match(file, "term:(.*):(%a+)") - return mtch ~= nil and mtch or vim.fn.fnamemodify(vim.env.SHELL, ':t') - elseif file == '' then - return '[No Name]' - else - return M.fileTitle(vim.fn.simplify(file)) + if buftype == "help" then + return "help:" .. vim.fn.fnamemodify(tail, ':r') + elseif filetype == "netrw" then + return file == "" and "netrw" or vim.fn.fnamemodify(file, ':p:~') + elseif buftype ~= "" then + return buftype + elseif file == "" then + return filetype == "" and "[No Name]" or filetype + elseif vim.tbl_contains(M.moduleNames, tail) then + return vim.fn.fnamemodify(vim.fn.fnamemodify(file, ':p:~:h'), ':t') .. "/" .. tail -- e.g. minitab/init.lua end + + return tail end M.modified = function(bufnr) - return vim.fn.getbufvar(bufnr, '&modified') == 1 and '+' or '' + return vim.fn.getbufvar(bufnr, '&modified') == 1 and M.modifiedC or "" end M.windowCount = function(index, hl) - local nwins = vim.fn.tabpagewinnr(index, '$') - return nwins > 1 and '%#TabLineSel#' .. nwins .. hl or '' + local nwins = #vim.tbl_filter(function(winnr) + return vim.fn.win_gettype(winnr) == "" -- windows will appear or disappear at random when editing files etc for no discernible reason + end, vim.api.nvim_tabpage_list_wins(index)) + return nwins > 1 and '%#TabLineSel#' .. nwins .. hl or "" end -M.separator = function(index) - return (index < vim.fn.tabpagenr('$') and '%#TabLine#|' or '') +M.separator = function(index, hl) + return (index < vim.fn.tabpagenr('$') and '%#TabLine#' .. M.separatorC or "") end M.cell = function(index) @@ -66,20 +47,20 @@ M.cell = function(index) local bufnr = buflist[winnr] local hl = (isSelected and '%#TabLineSel#' or '%#TabLine#') - local prefix = M.windowCount(index, hl) .. M.modified(bufnr) .. ' ' - return hl .. '%' .. index .. 'T' .. ' ' .. - (prefix == ' ' and '' or prefix) .. - M.title(bufnr) .. ' ' .. + local prefix = M.windowCount(index, hl) .. M.modified(bufnr) .. " " + return hl .. '%' .. index .. 'T' .. " " .. + (prefix == " " and "" or prefix) .. + M.title(bufnr, isSelected) .. " " .. M.separator(index) end M.tabline = function() - local line = '' + local line = "" for i = 1, vim.fn.tabpagenr('$'), 1 do line = line .. M.cell(i) end line = line .. '%#TabLineFill#%=' - if vim.fn.tabpagenr('$') > 1 then + if vim.fn.tabpagenr("$") > 1 then line = line .. '%#TabLine#%999XX' end return line @@ -92,7 +73,7 @@ local setup = function(opts) end end - vim.opt.tabline = '%!v:lua.require\'minitab\'.helpers.tabline()' + vim.opt.tabline = "%!v:lua.require'minitab'.helpers.tabline()" end return { diff --git a/minitab b/minitab deleted file mode 100644 index 29eebd9..0000000 --- a/minitab +++ /dev/null @@ -1,3 +0,0 @@ -[master 68779e1] cleantab - - 2 files changed, 6 insertions(+), 6 deletions(-) - rename lua/{cleantab => minitab}/init.lua (97%) -- cgit v1.2.3