Closed ls-devs closed 5 months ago
Actually, I ended up doing something like this :
EDIT : Edited code after some tweaks, ended up with something comfortable for me; but still gave me a headache. Is there any easier solution for this ?
local getTabName = function(tab)
local tabTail = vim.fn.fnamemodify(tab.name(), "%:t")
local tabName = ""
if string.len(tabTail) > 25 then
local fileExt = string.match(tabTail, "[^.]+$")
tabName = string.sub(tabTail, 0, 22 - string.len(fileExt)) .. "..." .. fileExt
end
if string.find(tabTail, "Floating") then
if vim.bo.filetype == "" then
local tail = vim.fn.expand("%:t")
if string.find(tail, "toggleterm") then
local pID = string.gsub(tail, "%d+:", "")
tabName = string.gsub(pID, ";#toggleterm#%d+", "")
end
if string.find(tail, "npm") then
tabName = string.gsub(tail, "%d+:", "")
end
else
tabName = vim.bo.filetype
end
end
if string.find(tab.name(), "%[%No Name]%[%d+%+%]") and string.find(vim.bo.filetype, "Overseer") then
tabName = vim.bo.filetype
end
if tabName == "" then
tabName = tab.name()
end
return tabName
end
But I feel like it's an endless fight. Is there any solution I can achieve this or not really ?
For now, the better way to set it is to add the option line option. You can find windows from tabid. and get the file type from the window ID.
{
tab_name = {
name_fallback = function()
local winid = vim.api.nvim_get_current_tabpage()
local bufid = vim.api.nvim_win_get_buf(winid)
local file_type = vim.api.nvim_buf_get_option(bufid, "filetype")
if file_type == "Overseer" or file_type == "Aerial" then
return file_type
end
return "[NO Name]"
end,
},
}
Welcome to more feedback and discussion.
I plan to refactor the documentation to add more instructions and some cookbooks. That will make this more easy to use.
@nanozuki Thanks for your reply. Unfortunately, the solution you provide leads me to a bug :
E5108: Error executing lua /home/ls-devs/.config/nvim/lua/ls-devs/plugins/ui/tabby.lua:7: Invalid window id: 1
I'm sorry I use a wrong api, the code should be:
{
tab_name = {
name_fallback = function(tabid)
local winid = vim.api.nvim_tabpage_get_win(tabid)
local bufid = vim.api.nvim_win_get_buf(winid)
local file_type = vim.api.nvim_buf_get_option(bufid, "filetype")
if file_type == "Overseer" or file_type == "Aerial" then
return file_type
end
return "[No Name]"
end,
},
}
I'm sorry I use a wrong api, the code should be:
{ tab_name = { name_fallback = function(tabid) local winid = vim.api.nvim_tabpage_get_win(tabid) local bufid = vim.api.nvim_win_get_buf(winid) local file_type = vim.api.nvim_buf_get_option(bufid, "filetype") if file_type == "Overseer" or file_type == "Aerial" then return file_type end return "[No Name]" end, }, }
Can confirm it's working. Thanks for the help !
Hi, I was wondering if there's a way we can set the tab name to
vim.bo.filetype
instead of using[No Name]
on certain window likeOverseer
orAerial
for example ?Please see actually tab name when openning![image](https://github.com/nanozuki/tabby.nvim/assets/58638832/72bc7f40-f471-43f9-b335-414574328804)
Overseer
:Actually
tabby
config :