Skip to content

polirritmico/lazy-local-patcher.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🌀 Lazy local patcher

Pull Requests GitHub last commit GitHub issues

🐧 Description

Sometimes, I need to apply small patches to a plugin to fulfill a very niche use case or to fix something without waiting for the PR to reach upstream. However, when doing so, Lazy can't sync the repo because there are local changes.

This small plugin addresses this issue by automatically applying the patches through git commands (if possible) and reverting them before Lazy starts its lazy magic.


Before:

Before

After:

After


📋 Requirements

📦 Installation

return {
    "polirritmico/lazy-local-patcher.nvim",
    config = true,
    ft = "lazy", -- for lazy loading
}

🚀 Usage

⚙️ Setup

Create the patches directory or the plugin will complain about the missing dir: (default path)

$ mkdir ~/.config/nvim/patches

Here you could add your patches. Two considerations:

  1. Only one file per plugin.
  2. The name of the patch should match the repository name. (More precisely, the directory name inside the Lazy root folder). e.g.: nvim-treesitter.patch

⚙️ Configuration

Custom folders could be passed to the setup function:

require("lazy-local-patcher").setup({
    lazy_path = "/custom/root/lazy/path", -- directory where lazy install the plugins
    patches_path = "/custom/patch/path", -- directory where diff patches files are stored
})

Defaults

Lazy local patcher comes with the following defaults:

local defaults = {
    lazy_path = vim.fn.stdpath("data") .. "/lazy", -- directory where lazy install the plugins
    patches_path = vim.fn.stdpath("config") .. "/patches", -- directory where diff patches files are stored
}

Patches

Patches are applied using:

git -C <plugin_path_in_Lazy_root> apply --ignore-space-change <patch>

Example of patch creation:

cd .local/share/nvim/lazy/nvim-treesitter
nvim edit/some/file
git diff | tee ~/.config/nvim/patches/nvim-treesitter.patch

Now enter into Nvim and sync the plugin with Lazy.

Manual executions

You could use apply_all or restore_all functions to manually apply/restore all patches inside the patches-path folder:

:lua require("lazy-local-patcher").apply_all()
[patches: nvim-treesitter.patch] Applying patch...
[patches: nvim-treesitter.patch] Done
:lua require("lazy-local-patcher").restore_all()
[patches: nvim-treesitter.patch] Restoring plugin repository...
[patches: nvim-treesitter.patch] Done

🌱 Contributions

While this plugin is primarily designed for my personal use and tailored to a very specific use case, suggestions, issues, or pull requests are very welcome.

Enjoy

About

Apply local patches to plugins installed through lazy.nvim

Topics

Resources

License

Stars

Watchers

Forks

Languages