nanozuki / tabby.nvim

A declarative, highly configurable, and neovim style tabline plugin. Use your nvim tabs as a workspace multiplexer!
MIT License
607 stars 21 forks source link

feat: buf_name override #155

Closed capsey closed 4 days ago

capsey commented 2 months ago

Add a new option in TabbyLineOption.buf_name called override which is a function that takes bufid and returns optional string. If nil is returned, win.buf_name() returns as normal, but if any string is returned, win.buf_name() returns it without any changes.

It's useful for giving distinctive names to temporary buffers that otherwise have either unhelpful or empty names. For example, for vim-fugitive temp buffers:

require('tabby').setup({
  option = {
    buf_name = {
      override = function(bufid)
        local filetype = vim.api.nvim_buf_get_option(bufid, 'filetype')
        if filetype ~= 'git' then return nil end  -- Display default name for everything else

        local fugitive_info = vim.fn.FugitiveResult(vim.api.nvim_buf_get_name(bufid))
        return 'git ' .. table.concat(fugitive_info.args, ' ')  -- Display respective git command
      end,
    },
  },
})
nanozuki commented 4 days ago

After #159 was merged, there were too many conflicts, so I rewrote them and merged them in #161.