From 4d6d9cb297b67753056787054e7b6616a895318c Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Wed, 27 Nov 2024 22:04:23 -0600 Subject: cleantab - --- README.md | 10 ++--- lua/cleantab/init.lua | 100 -------------------------------------------------- lua/minitab/init.lua | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 105 deletions(-) delete mode 100644 lua/cleantab/init.lua create mode 100644 lua/minitab/init.lua diff --git a/README.md b/README.md index fa82e49..c2f5cc0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# cleantab.nvim +# minitab.nvim Fork of [`alvarosevilla95/luatab.nvim`](https://github.com/alvarosevilla95/luatab.nvim) @@ -10,23 +10,23 @@ Fork of ## Install Using [`lazy.nvim`](https://github.com/folke/lazy.nvim) ```lua -{ 'https://git.tjkeller.xyz/cleantab.nvim' } +{ 'https://git.tjkeller.xyz/minitab.nvim' } ``` ## Usage Add this to your init.lua: ```lua -require('cleantab').setup{} +require('minitab').setup{} ``` ## Configuration The plugin calls the `helpers.tabline` function to render the line. It uses the other functions defined in `helpers`, such as `cell,separator,devicon`. -You can pass overrides for any of these functions in `setup`. Please see `lua/cleantab/init.lua` for details. +You can pass overrides for any of these functions in `setup`. Please see `lua/minitab/init.lua` for details. Example: ``` -require('cleantab').setup{ +require('minitab').setup{ title = function() return '' end, modified = function() return '' end, windowCount = function() return '' end, diff --git a/lua/cleantab/init.lua b/lua/cleantab/init.lua deleted file mode 100644 index aa4a974..0000000 --- a/lua/cleantab/init.lua +++ /dev/null @@ -1,100 +0,0 @@ -local M = {} - -M.fileTitle = function(file) - file = vim.fn.fnamemodify(file, ':p:~') - local tail = vim.fn.fnamemodify(file, ':t') - - if not tail then - return vim.fn.fnamemodify(file, ':p:~:h') .. '/' -- e.g. ~/dir/ - elseif tail == 'init.lua' - or tail == '__init__.py' then - return vim.fn.fnamemodify(vim.fn.fnamemodify(file, ':h'), ':t') .. '/' .. tail -- e.g. luatab/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)) - end -end - -M.modified = function(bufnr) - return vim.fn.getbufvar(bufnr, '&modified') == 1 and '+' or '' -end - -M.windowCount = function(index, hl) - local nwins = vim.fn.tabpagewinnr(index, '$') - return nwins > 1 and '%#TabLineSel#' .. nwins .. hl or '' -end - -M.separator = function(index) - return (index < vim.fn.tabpagenr('$') and '%#TabLine#|' or '') -end - -M.cell = function(index) - local isSelected = vim.fn.tabpagenr() == index - local buflist = vim.fn.tabpagebuflist(index) - local winnr = vim.fn.tabpagewinnr(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) .. ' ' .. - M.separator(index) -end - -M.tabline = function() - 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 - line = line .. '%#TabLine#%999XX' - end - return line -end - -local setup = function(opts) - if opts then - for key, value in pairs(opts) do - M[key] = value - end - end - - vim.opt.tabline = '%!v:lua.require\'luatab\'.helpers.tabline()' -end - -return { - helpers = M, - setup = setup, -} diff --git a/lua/minitab/init.lua b/lua/minitab/init.lua new file mode 100644 index 0000000..0504d42 --- /dev/null +++ b/lua/minitab/init.lua @@ -0,0 +1,100 @@ +local M = {} + +M.fileTitle = function(file) + file = vim.fn.fnamemodify(file, ':p:~') + local tail = vim.fn.fnamemodify(file, ':t') + + if not tail then + return vim.fn.fnamemodify(file, ':p:~:h') .. '/' -- e.g. ~/dir/ + elseif tail == 'init.lua' + or tail == '__init__.py' then + return vim.fn.fnamemodify(vim.fn.fnamemodify(file, ':h'), ':t') .. '/' .. tail -- e.g. luatab/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)) + end +end + +M.modified = function(bufnr) + return vim.fn.getbufvar(bufnr, '&modified') == 1 and '+' or '' +end + +M.windowCount = function(index, hl) + local nwins = vim.fn.tabpagewinnr(index, '$') + return nwins > 1 and '%#TabLineSel#' .. nwins .. hl or '' +end + +M.separator = function(index) + return (index < vim.fn.tabpagenr('$') and '%#TabLine#|' or '') +end + +M.cell = function(index) + local isSelected = vim.fn.tabpagenr() == index + local buflist = vim.fn.tabpagebuflist(index) + local winnr = vim.fn.tabpagewinnr(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) .. ' ' .. + M.separator(index) +end + +M.tabline = function() + 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 + line = line .. '%#TabLine#%999XX' + end + return line +end + +local setup = function(opts) + if opts then + for key, value in pairs(opts) do + M[key] = value + end + end + + vim.opt.tabline = '%!v:lua.require\'minitab\'.helpers.tabline()' +end + +return { + helpers = M, + setup = setup, +} -- cgit v1.2.3