aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore52
-rw-r--r--LICENSE1
-rw-r--r--Makefile9
-rw-r--r--README.md21
-rw-r--r--lua/cleantab/init.lua100
-rw-r--r--lua/luatab/highlight.lua40
-rw-r--r--lua/luatab/init.lua130
7 files changed, 108 insertions, 245 deletions
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index 32ae60e..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,52 +0,0 @@
-# Compiled Lua sources
-luac.out
-
-# luarocks build files
-*.src.rock
-*.zip
-*.tar.gz
-
-# Object files
-*.o
-*.os
-*.ko
-*.obj
-*.elf
-
-# Precompiled Headers
-*.gch
-*.pch
-
-# Libraries
-*.lib
-*.a
-*.la
-*.lo
-*.def
-*.exp
-
-# Shared objects (inc. Windows DLLs)
-*.dll
-*.so
-*.so.*
-*.dylib
-
-# Executables
-*.exe
-*.out
-*.app
-*.i*86
-*.x86_64
-*.hex
-
-# ctags
-tags
-
-# helptags
-doc/tags
-
-.DS_Store
-
-.github
-.lua-format
-.luacheckrc
diff --git a/LICENSE b/LICENSE
index 869fc98..cfc0f80 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,7 @@
MIT License
Copyright (c) 2021 Alvaro Sevilla
+Copyright (c) 2024 Tim Keller <tjkeller.xyz>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 3f3f8d6..0000000
--- a/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
-.DEFAULT_GOAL = check
-
-lint:
- @luacheck lua/luatab
-
-format:
- @for file in `find . -name '*.lua'`;do lua-format $$file -i; done;
-
-check: lint test
diff --git a/README.md b/README.md
index e3376b9..fa82e49 100644
--- a/README.md
+++ b/README.md
@@ -1,42 +1,35 @@
-# luatab.nvim
+# cleantab.nvim
-<p align="center">
- <img src="https://github.com/alvarosevilla95/luatab.nvim/blob/master/pics/tabline.png" />
-</p>
+Fork of
+[`alvarosevilla95/luatab.nvim`](https://github.com/alvarosevilla95/luatab.nvim)
## Features
* Just a lua rewrite of the tabline render function
* No weird mixing buffers and tabs stuff
## Install
-Using packer.nvim:
-```lua
-use { 'alvarosevilla95/luatab.nvim', requires='nvim-tree/nvim-web-devicons' }
-```
-
Using [`lazy.nvim`](https://github.com/folke/lazy.nvim)
```lua
-{ 'alvarosevilla95/luatab.nvim', dependencies = { 'nvim-tree/nvim-web-devicons' } }
+{ 'https://git.tjkeller.xyz/cleantab.nvim' }
```
## Usage
Add this to your init.lua:
```lua
-require('luatab').setup{}
+require('cleantab').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/luatab/init.lua` for details.
+You can pass overrides for any of these functions in `setup`. Please see `lua/cleantab/init.lua` for details.
Example:
```
-require('luatab').setup{
+require('cleantab').setup{
title = function() return '' end,
modified = function() return '' end,
windowCount = function() return '' end,
- devicon = function() return '' end,
separator = function() return '' end,
}
```
diff --git a/lua/cleantab/init.lua b/lua/cleantab/init.lua
new file mode 100644
index 0000000..aa4a974
--- /dev/null
+++ b/lua/cleantab/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\'luatab\'.helpers.tabline()'
+end
+
+return {
+ helpers = M,
+ setup = setup,
+}
diff --git a/lua/luatab/highlight.lua b/lua/luatab/highlight.lua
deleted file mode 100644
index c696135..0000000
--- a/lua/luatab/highlight.lua
+++ /dev/null
@@ -1,40 +0,0 @@
--- Shamelessly stolen from
--- https://github.com/hoob3rt/lualine.nvim/blob/master/lua/lualine/utils/utils.lua
-
-local M = {}
-
-M.highlight = function(name, foreground, background)
- local command = {'highlight', name}
- if foreground and foreground ~= 'none' then
- table.insert(command, 'guifg=' .. foreground)
- end
- if background and background ~= 'none' then
- table.insert(command, 'guibg=' .. background)
- end
- vim.cmd(table.concat(command, ' '))
-end
-
-M.create_component_highlight_group = function(color, highlight_tag)
- if color.bg and color.fg then
- local highlight_group_name = table.concat({'luatab', highlight_tag}, '_')
- M.highlight(highlight_group_name, color.fg, color.bg)
- return highlight_group_name
- end
-end
-
-M.extract_highlight_colors = function(color_group, scope)
- if vim.fn.hlexists(color_group) == 0 then return nil end
- local color = vim.api.nvim_get_hl_by_name(color_group, true)
- if color.background ~= nil then
- color.bg = string.format('#%06x', color.background)
- color.background = nil
- end
- if color.foreground ~= nil then
- color.fg = string.format('#%06x', color.foreground)
- color.foreground = nil
- end
- if scope then return color[scope] end
- return color
-end
-
-return M
diff --git a/lua/luatab/init.lua b/lua/luatab/init.lua
deleted file mode 100644
index d18d6e7..0000000
--- a/lua/luatab/init.lua
+++ /dev/null
@@ -1,130 +0,0 @@
-local M = {}
-
-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 vim.fn.pathshorten(vim.fn.fnamemodify(file, ':p:~:t'))
- end
-end
-
-M.modified = function(bufnr)
- return vim.fn.getbufvar(bufnr, '&modified') == 1 and '[+] ' or ''
-end
-
-M.windowCount = function(index)
- local nwins = vim.fn.tabpagewinnr(index, '$')
- return nwins > 1 and '(' .. nwins .. ') ' or ''
-end
-
-M.devicon = function(bufnr, isSelected)
- local icon, devhl
- local file = vim.fn.fnamemodify(vim.fn.bufname(bufnr), ':t')
- local buftype = vim.fn.getbufvar(bufnr, '&buftype')
- local filetype = vim.fn.getbufvar(bufnr, '&filetype')
- local devicons = require'nvim-web-devicons'
- if filetype == 'TelescopePrompt' then
- icon, devhl = devicons.get_icon('telescope')
- elseif filetype == 'fugitive' then
- icon, devhl = devicons.get_icon('git')
- elseif filetype == 'vimwiki' then
- icon, devhl = devicons.get_icon('markdown')
- elseif buftype == 'terminal' then
- icon, devhl = devicons.get_icon('zsh')
- else
- icon, devhl = devicons.get_icon(file, vim.fn.expand('#'..bufnr..':e'))
- end
- if icon then
- local h = require'luatab.highlight'
- local fg = h.extract_highlight_colors(devhl, 'fg')
- local bg = h.extract_highlight_colors('TabLineSel', 'bg')
- local hl = h.create_component_highlight_group({bg = bg, fg = fg}, devhl)
- local selectedHlStart = (isSelected and hl) and '%#'..hl..'#' or ''
- local selectedHlEnd = isSelected and '%#TabLineSel#' or ''
- return selectedHlStart .. icon .. selectedHlEnd .. ' '
- end
- return ''
-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#')
-
- return hl .. '%' .. index .. 'T' .. ' ' ..
- M.windowCount(index) ..
- M.title(bufnr) .. ' ' ..
- M.modified(bufnr) ..
- M.devicon(bufnr, isSelected) .. '%T' ..
- 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)
- opts = opts or {}
- if opts.title then M.title = opts.title end
- if opts.modified then M.modified = opts.modified end
- if opts.windowCount then M.windowCount = opts.windowCount end
- if opts.devicon then M.devicon = opts.devicon end
- if opts.separator then M.separator = opts.separator end
- if opts.cell then M.cell = opts.cell end
- if opts.tabline then M.tabline = opts.tabline end
-
- vim.opt.tabline = '%!v:lua.require\'luatab\'.helpers.tabline()'
-end
-
-local warning = function()
- error [[
-Hi, I've updated luatab.nvim to allow some proper configuration. As a result, I need to make a breaking change to the config. Apologies for the inconvinence.
-If you had:
- vim.o.tabline = '%!v:lua.require\'luatab\'.tabline()'
-please replace it with
- require('luatab').setup({})
-]]
-end
-
-return {
- helpers = M,
- setup = setup,
- tabline = warning,
-}