Skip to content

gitsigns _on_attach_pre hook to show git decorations for files tracked by yadm

License

Notifications You must be signed in to change notification settings

purarue/gitsigns-yadm.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gitsigns-yadm.nvim

This uses the gitsigns _on_attach_pre function to check if the currently attached buffer is file tracked by yadm, highlighting the buffer properly if it is.

Installation

Install the plugin with your plugin manager, and then add a _on_attach_pre function to your gitsigns configuration, passing the callback to the yadm_signs function:

require('gitsigns').setup({
    _on_attach_pre = function(_, callback)
        require("gitsigns-yadm").yadm_signs(callback)
    end,
    -- other gitsigns configuration...
    on_attach = function(bufnr)
})

See below for examples using lazy.

Configuration

If using a standard yadm setup, you likely won't need to configure anything.

The default computed values are:

{
    homedir = os.getenv("HOME"),
    yadm_repo_git = vim.fn.expand("~/.local/share/yadm/repo.git"),
    shell_timeout_ms = 2000, -- how many milliseconds to wait for yadm to finish
}

Call setup to override the defaults:

require("gitsigns-yadm").setup({
    yadm_repo_git = "~/.config/yadm/repo.git",
    shell_timeout_ms = 1000,
})

If you want to disable this when yadm is not installed, you can use vim.fn.executable to check before running the callback:

_on_attach_pre = function(_, callback)
    if vim.fn.executable("yadm") == 1 then
        require("gitsigns-yadm").yadm_signs(callback)
    else
        callback()
    end
end,

Install Examples

With lazy:

{
    "lewis6991/gitsigns.nvim",
    dependencies = {
        "nvim-lua/plenary.nvim",
        {
            "purarue/gitsigns-yadm.nvim",
            opts = {
                shell_timeout_ms = 1000,
            },
        },
    },
    opts = {
        _on_attach_pre = function(_, callback)
            require("gitsigns-yadm").yadm_signs(callback)
        end,
        -- other configuration for gitsigns...
    },
}

Since this doesn't require calling setup (unless you want to configure the defaults), in accordance with lazys best practices you could also do the following:

{
    {
        "purarue/gitsigns-yadm.nvim",
        lazy = true,
    },
    {
        "nvim-lua/plenary.nvim",
        lazy = true,
    },
    {
        "lewis6991/gitsigns.nvim",
        opts = {
            ...
            _on_attach_pre = function(_, callback)
                require("gitsigns-yadm").yadm_signs(callback)
            end,
            ...
        }
    }
}

About

gitsigns _on_attach_pre hook to show git decorations for files tracked by yadm

Topics

Resources

License

Stars

Watchers

Forks