From c7a600c3f3878f3c60b03b2f68c2080c742793e8 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Thu, 23 Jan 2025 23:29:40 -0600 Subject: [PATCH] plugins/git-worktree: migrate to mkNeovimPlugin --- plugins/by-name/git-worktree/default.nix | 103 ++++++++---------- plugins/by-name/git-worktree/deprecations.nix | 9 ++ .../plugins/by-name/git-worktree/default.nix | 11 +- 3 files changed, 60 insertions(+), 63 deletions(-) create mode 100644 plugins/by-name/git-worktree/deprecations.nix diff --git a/plugins/by-name/git-worktree/default.nix b/plugins/by-name/git-worktree/default.nix index c5ecf8e878..7f521ea393 100644 --- a/plugins/by-name/git-worktree/default.nix +++ b/plugins/by-name/git-worktree/default.nix @@ -5,64 +5,59 @@ ... }: let - cfg = config.plugins.git-worktree; + inherit (lib.nixvim) defaultNullOpts; in -{ - options = { - plugins.git-worktree = { - enable = lib.mkEnableOption "git-worktree"; +lib.nixvim.plugins.mkNeovimPlugin { + name = "git-worktree"; + packPathName = "git-worktree.nvim"; + package = "git-worktree-nvim"; + + maintainers = [ lib.maintainers.khaneliman ]; - package = lib.mkPackageOption pkgs "git-worktree" { - default = [ - "vimPlugins" - "git-worktree-nvim" - ]; - }; + settingsOptions = { + change_directory_command = defaultNullOpts.mkStr "cd" '' + The vim command used to change to the new worktree directory. + Set this to `tcd` if you want to only change the `pwd` for the current vim Tab. + ''; - gitPackage = lib.mkPackageOption pkgs "git" { - nullable = true; - }; + update_on_change = defaultNullOpts.mkBool true '' + If set to true updates the current buffer to point to the new work tree if the file is found in the new project. + Otherwise, the following command will be run. + ''; - enableTelescope = lib.mkEnableOption "telescope integration"; + update_on_change_command = defaultNullOpts.mkStr "e ." '' + The vim command to run during the `update_on_change` event. + Note, that this command will only be run when the current file is not found in the new worktree. + This option defaults to `e .` which opens the root directory of the new worktree. + ''; - changeDirectoryCommand = lib.nixvim.defaultNullOpts.mkStr "cd" '' - The vim command used to change to the new worktree directory. - Set this to `tcd` if you want to only change the `pwd` for the current vim Tab. - ''; + clear_jumps_on_change = defaultNullOpts.mkBool true '' + If set to true every time you switch branches, your jumplist will be cleared so that you don't + accidentally go backward to a different branch and edit the wrong files. + ''; - updateOnChange = lib.nixvim.defaultNullOpts.mkBool true '' - If set to true updates the current buffer to point to the new work tree if the file is found in the new project. - Otherwise, the following command will be run. - ''; + autopush = defaultNullOpts.mkBool false '' + When creating a new worktree, it will push the branch to the upstream then perform a `git rebase`. + ''; + }; - updateOnChangeCommand = lib.nixvim.defaultNullOpts.mkStr "e ." '' - The vim command to run during the `update_on_change` event. - Note, that this command will only be run when the current file is not found in the new worktree. - This option defaults to `e .` which opens the root directory of the new worktree. - ''; + settingsExample = { + change_directory_command = "z"; + update_on_change = false; + clear_jumps_on_change = false; + autopush = true; + }; - clearJumpsOnChange = lib.nixvim.defaultNullOpts.mkBool true '' - If set to true every time you switch branches, your jumplist will be cleared so that you don't - accidentally go backward to a different branch and edit the wrong files. - ''; + extraOptions = { + enableTelescope = lib.mkEnableOption "telescope integration"; - autopush = lib.nixvim.defaultNullOpts.mkBool false '' - When creating a new worktree, it will push the branch to the upstream then perform a `git rebase`. - ''; + gitPackage = lib.mkPackageOption pkgs "git" { + nullable = true; }; }; - config = - let - setupOptions = with cfg; { - enabled = cfg.enable; - change_directory_command = cfg.changeDirectoryCommand; - update_on_change = cfg.updateOnChange; - update_on_change_command = cfg.updateOnChangeCommand; - clearjumps_on_change = cfg.clearJumpsOnChange; - inherit autopush; - }; - in + extraConfig = + cfg: lib.mkIf cfg.enable { assertions = [ { @@ -71,20 +66,10 @@ in } ]; - extraPlugins = with pkgs.vimPlugins; [ - cfg.package - plenary-nvim - ]; - extraPackages = [ cfg.gitPackage ]; - extraConfigLua = - let - telescopeCfg = ''require("telescope").load_extension("git_worktree")''; - in - '' - require('git-worktree').setup(${lib.nixvim.toLuaObject setupOptions}) - ${if cfg.enableTelescope then telescopeCfg else ""} - ''; + plugins.telescope.enabledExtensions = lib.mkIf cfg.enableTelescope [ "git_worktree" ]; }; + + inherit (import ./deprecations.nix) optionsRenamedToSettings; } diff --git a/plugins/by-name/git-worktree/deprecations.nix b/plugins/by-name/git-worktree/deprecations.nix new file mode 100644 index 0000000000..d9b6df0aed --- /dev/null +++ b/plugins/by-name/git-worktree/deprecations.nix @@ -0,0 +1,9 @@ +{ + optionsRenamedToSettings = [ + "changeDirectoryCommand" + "updateOnChange" + "updateOnChangeCommand" + "clearJumpsOnChange" + "autopush" + ]; +} diff --git a/tests/test-sources/plugins/by-name/git-worktree/default.nix b/tests/test-sources/plugins/by-name/git-worktree/default.nix index e33c34dcc6..bda9091a88 100644 --- a/tests/test-sources/plugins/by-name/git-worktree/default.nix +++ b/tests/test-sources/plugins/by-name/git-worktree/default.nix @@ -12,10 +12,13 @@ enable = true; enableTelescope = true; - changeDirectoryCommand = "tcd"; - updateOnChange = true; - updateOnChangeCommand = "e ."; - clearJumpsOnChange = true; + + settings = { + change_directory_command = "tcd"; + update_on_change = true; + update_on_change_command = "e ."; + clear_jumps_on_change = true; + }; }; plugins.web-devicons.enable = true;