Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow enabling extensions per buftype #1125

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

martinparadiso
Copy link

Context and motivation

I was writing an extension for the special terminal buffer
and realized in has no filetype like the quickfix window,
instead filetype is empty and the buftype is 'terminal'.
Currently here is no direct way to set an special bufferline
for the terminal buffer.

Proposed change

Add a buftypes table to the extension table, allowing to
filter extensions by buftype; and the corresponding
implementation.

Some basic test cases were added.

Example extension

Example of an extension for terminal buffers:

Source code
local terminal_extension = {
    sections = {

        lualine_a = { function()
            return 'TERMINAL'
        end },

        lualine_b = {
            function()
                local name = vim.api.nvim_buf_get_name(0)
                local match = string.match(vim.split(name, ' ')[1], 'term:.*:(%a+)')
                return match ~= nil and match or vim.fn.fnamemodify(vim.env.SHELL, ':t')
            end },
        lualine_c = {
            function()
                return vim.b.term_title
            end
        },
        lualine_x = {},
        lualine_y = {

            function()
                local dev, _ = require('nvim-web-devicons').get_icon('zsh')
                return dev
            end
        },
        lualine_z = {},
    },
    buftypes = { 'terminal' },
}

image

Add a `buftypes` parameter to the extension table; allowing to
filter by current buftype in addition to filetype.
@shadmansaleh
Copy link
Member

Can you include the terminal extension too? It seems nice to have plus will be an example implementation.

@martinparadiso
Copy link
Author

Done, should be working with and without web-devicons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants