Custom tabline

This commit is contained in:
2026-06-28 13:34:02 +02:00
parent e41cd21a1d
commit c0a6c5848a
3 changed files with 75 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
local M = {}
local function truncate_label(label, max_width)
if vim.fn.strdisplaywidth(label) <= max_width then
return label
end
return vim.fn.strcharpart(label, 0, max_width - 1) .. ""
end
local function terminal_label(bufnr)
local term_title = vim.b[bufnr].term_title
if type(term_title) == "string" and term_title ~= "" then
local cmd = vim.fn.fnamemodify(term_title:match("^%S+") or "", ":t")
if cmd ~= "" then
return cmd
end
end
local bufname = vim.api.nvim_buf_get_name(bufnr)
local cmd = bufname:match("term://.*:(.+)$")
if cmd then
local first_word = vim.split(cmd, " ", { plain = true })[1] or ""
local basename = vim.fn.fnamemodify(first_word, ":t")
if basename ~= "" then
return basename
end
end
return "terminal"
end
local function tab_label(tabnr)
local buflist = vim.fn.tabpagebuflist(tabnr)
local winnr = vim.fn.tabpagewinnr(tabnr)
local bufnr = buflist[winnr]
local label
if vim.bo[bufnr].buftype == "terminal" then
label = terminal_label(bufnr)
else
local bufname = vim.api.nvim_buf_get_name(bufnr)
label = bufname == "" and "[No Name]" or vim.fn.fnamemodify(bufname, ":t")
end
if vim.bo[bufnr].modified then
label = label .. " +"
end
return truncate_label(label, 18)
end
function M.render()
local current = vim.fn.tabpagenr()
local last = vim.fn.tabpagenr("$")
local parts = {}
for index = 1, last do
parts[#parts + 1] = index == current and "%#TabLineSel#" or "%#TabLine#"
parts[#parts + 1] = "%" .. index .. "T"
parts[#parts + 1] = " " .. index .. " " .. tab_label(index) .. " "
end
parts[#parts + 1] = "%#TabLineFill#%T"
return table.concat(parts)
end
_G.RomanzyTabline = M.render
return M

View File

@@ -32,6 +32,7 @@ o.incsearch = true -- Updates search matches as you type.
o.updatetime = 50 -- Reduces idle delay for swap and CursorHold events.
o.spelllang = { "en_us" } -- Uses US English for spell checking.
o.shell = "bash" -- Runs shell commands through bash.
o.tabline = "%!v:lua.RomanzyTabline()" -- Shows native tabs with custom labels.
-- Only show the invisible characters inside the code editing buffers
vim.cmd([[autocmd BufWinEnter * if &buftype != '' | setlocal nolist | endif]])

View File

@@ -5,3 +5,6 @@ require("romanzy.plugins.telescope")
require("romanzy.plugins.nvim-treesitter")
require("romanzy.plugins.lsp")
-- require("romanzy.plugins.header42")
-- custom "plugins"
require("romanzy.custom.tabline")