nanozuki / tabby.nvim

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

feat: buf_name override #155

Open capsey opened 1 month ago

capsey commented 1 month 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,
    },
  },
})