From 69266437beaac970568d12a46766706c72f361b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Tue, 6 May 2025 23:11:05 +0200 Subject: [PATCH] plugins/hunk: init Add support for [hunk.nvim][1], a plugin for splitting diffs. Also add myself as a maintainer for it. [1]: https://github.com/julienvincent/hunk.nvim --- plugins/by-name/hunk/default.nix | 50 ++++++++++ .../plugins/by-name/hunk/default.nix | 94 +++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 plugins/by-name/hunk/default.nix create mode 100644 tests/test-sources/plugins/by-name/hunk/default.nix diff --git a/plugins/by-name/hunk/default.nix b/plugins/by-name/hunk/default.nix new file mode 100644 index 00000000..b4c32a49 --- /dev/null +++ b/plugins/by-name/hunk/default.nix @@ -0,0 +1,50 @@ +{ + lib, + helpers, + config, + ... +}: +lib.nixvim.plugins.mkNeovimPlugin { + name = "hunk"; + packPathName = "hunk.nvim"; + package = "hunk-nvim"; + + description = '' + A tool for splitting diffs in Neovim. + + If you wish to display icons in the file tree you should enable either + `plugins.web-devicons` or `plugins.mini`. If using `plugins.mini`, you + must enable the `icons` module. + ''; + + maintainers = [ lib.maintainers.jalil-salame ]; + + extraConfig.plugins.nui.enable = lib.mkDefault true; # required dependency + + settingsExample = { + keys.global.quit = [ "x" ]; + + ui = { + tree = { + mode = "flat"; + width = 40; + }; + layout = "horizontal"; + }; + + hooks = { + on_tree_mount = + lib.nixvim.nestedLiteralLua # lua + '' + ---@param _context { buf: number, tree: NuiTree, opts: table } + function(_context) end + ''; + on_diff_mount = + lib.nixvim.nestedLiteralLua # lua + '' + ---@param _context { buf: number, win: number } + function(_context) end + ''; + }; + }; +} diff --git a/tests/test-sources/plugins/by-name/hunk/default.nix b/tests/test-sources/plugins/by-name/hunk/default.nix new file mode 100644 index 00000000..bedac4d6 --- /dev/null +++ b/tests/test-sources/plugins/by-name/hunk/default.nix @@ -0,0 +1,94 @@ +{ + empty = { + plugins.hunk.enable = true; + }; + + with-web-devicons = { + plugins.hunk.enable = true; + plugins.web-devicons.enable = true; + }; + + with-mini = { + plugins.hunk.enable = true; + plugins.mini = { + enable = true; + modules.icons = { }; + }; + }; + + example.plugins.hunk = { + enable = true; + settings = { + keys.global.quit = [ "x" ]; + + ui = { + tree = { + mode = "flat"; + width = 40; + }; + layout = "horizontal"; + }; + + hooks = { + on_tree_mount.__raw = "function(_context) end"; + on_diff_mount.__raw = "function(_context) end"; + }; + }; + }; + + # Taken directly from the plugin docs: https://github.com/julienvincent/hunk.nvim#configuration + defaults.plugins.hunk = { + enable = true; + settings = { + keys = { + global = { + quit = [ "q" ]; + accept = [ "" ]; + focus_tree = [ "e" ]; + }; + + tree = { + expand_node = [ + "l" + "" + ]; + collapse_node = [ + "h" + "" + ]; + + open_file = [ "" ]; + + toggle_file = [ "a" ]; + }; + + diff = { + toggle_line = [ "a" ]; + toggle_hunk = [ "A" ]; + }; + }; + + ui = { + tree = { + mode = "nested"; + width = 35; + }; + layout = "vertical"; + }; + + icons = { + selected = "󰡖"; + deselected = ""; + partially_selected = "󰛲"; + + folder_open = ""; + folder_closed = ""; + }; + + hooks = { + on_tree_mount.__raw = "function(_context) end"; + on_diff_mount.__raw = "function(_context) end"; + }; + }; + }; +}