From 8f5a85d4c82f133ebaff0745d99e79e2b8bc4034 Mon Sep 17 00:00:00 2001 From: Alexander Nortung Date: Sun, 17 Nov 2024 15:01:58 +0100 Subject: [PATCH] feat: Add keymap options to bufferline --- config/bufferlines/bufferline.nix | 261 ++++++++++++++++-------------- 1 file changed, 144 insertions(+), 117 deletions(-) diff --git a/config/bufferlines/bufferline.nix b/config/bufferlines/bufferline.nix index d139ac9..c10d3b0 100644 --- a/config/bufferlines/bufferline.nix +++ b/config/bufferlines/bufferline.nix @@ -1,135 +1,162 @@ { lib, config, ... }: { options = { - bufferline.enable = lib.mkEnableOption "Enable bufferline module"; - }; - config = lib.mkIf config.bufferline.enable { - plugins = { - bufferline = { - enable = true; - settings = { - options = { - separatorStyle = "thick"; # “slant”, “padded_slant”, “slope”, “padded_slope”, “thick”, “thin“ - offsets = [ - { - filetype = "neo-tree"; - text = "Neo-tree"; - highlight = "Directory"; - text_align = "left"; - } - ]; - }; - }; - }; - }; - keymaps = [ - { - mode = "n"; - key = ""; - action = "BufferLineCycleNext"; - options = { - desc = "Cycle to next buffer"; - }; - } + bufferline = { + enable = lib.mkEnableOption "Enable bufferline module"; - { - mode = "n"; - key = ""; - action = "BufferLineCyclePrev"; - options = { - desc = "Cycle to previous buffer"; + keymaps = { + enable = lib.mkOption { + type = lib.types.bool; + default = true; + description = "Enable default keymaps"; }; - } - { - mode = "n"; - key = ""; - action = "BufferLineCycleNext"; - options = { - desc = "Cycle to next buffer"; + enableHL = lib.mkOption { + type = lib.types.bool; + default = true; + description = "Enable keymaps for switching buffers with h and l"; }; - } - { - mode = "n"; - key = ""; - action = "BufferLineCyclePrev"; - options = { - desc = "Cycle to previous buffer"; + enableTab = lib.mkOption { + type = lib.types.bool; + default = true; + description = "Enable keymaps for switching buffers with Tab and S-Tab"; }; - } - - { - mode = "n"; - key = "bd"; - action = "bdelete"; - options = { - desc = "Delete buffer"; + }; + }; + }; + config = + let + cfg = config.bufferline; + in + lib.mkIf cfg.enable { + plugins = { + bufferline = { + enable = true; + settings = { + options = { + separatorStyle = "thick"; # “slant”, “padded_slant”, “slope”, “padded_slope”, “thick”, “thin“ + offsets = [ + { + filetype = "neo-tree"; + text = "Neo-tree"; + highlight = "Directory"; + text_align = "left"; + } + ]; + }; + }; }; - } + }; + keymaps = lib.mkIf cfg.keymaps.enable + ([ + { + mode = "n"; + key = "bd"; + action = "bdelete"; + options = { + desc = "Delete buffer"; + }; + } - { - mode = "n"; - key = "bb"; - action = "e #"; - options = { - desc = "Switch to Other Buffer"; - }; - } + { + mode = "n"; + key = "bb"; + action = "e #"; + options = { + desc = "Switch to Other Buffer"; + }; + } - # { - # mode = "n"; - # key = "`"; - # action = "e #"; - # options = { - # desc = "Switch to Other Buffer"; - # }; - # } + # { + # mode = "n"; + # key = "`"; + # action = "e #"; + # options = { + # desc = "Switch to Other Buffer"; + # }; + # } - { - mode = "n"; - key = "br"; - action = "BufferLineCloseRight"; - options = { - desc = "Delete buffers to the right"; - }; - } + { + mode = "n"; + key = "br"; + action = "BufferLineCloseRight"; + options = { + desc = "Delete buffers to the right"; + }; + } - { - mode = "n"; - key = "bl"; - action = "BufferLineCloseLeft"; - options = { - desc = "Delete buffers to the left"; - }; - } + { + mode = "n"; + key = "bl"; + action = "BufferLineCloseLeft"; + options = { + desc = "Delete buffers to the left"; + }; + } - { - mode = "n"; - key = "bo"; - action = "BufferLineCloseOthers"; - options = { - desc = "Delete other buffers"; - }; - } + { + mode = "n"; + key = "bo"; + action = "BufferLineCloseOthers"; + options = { + desc = "Delete other buffers"; + }; + } - { - mode = "n"; - key = "bp"; - action = "BufferLineTogglePin"; - options = { - desc = "Toggle pin"; - }; - } + { + mode = "n"; + key = "bp"; + action = "BufferLineTogglePin"; + options = { + desc = "Toggle pin"; + }; + } - { - mode = "n"; - key = "bP"; - action = "BufferLineGroupClose ungrouped"; - options = { - desc = "Delete non-pinned buffers"; - }; - } - ]; - }; + { + mode = "n"; + key = "bP"; + action = "BufferLineGroupClose ungrouped"; + options = { + desc = "Delete non-pinned buffers"; + }; + } + ] ++ (lib.optionals cfg.keymaps.enableTab [ + { + mode = "n"; + key = ""; + action = "BufferLineCycleNext"; + options = { + desc = "Cycle to next buffer"; + }; + } + + { + mode = "n"; + key = ""; + action = "BufferLineCyclePrev"; + options = { + desc = "Cycle to previous buffer"; + }; + } + ]) ++ (lib.optionals cfg.keymaps.enableHL [ + { + mode = "n"; + key = ""; + action = "BufferLineCycleNext"; + options = { + desc = "Cycle to next buffer"; + }; + } + + { + mode = "n"; + key = ""; + action = "BufferLineCyclePrev"; + options = { + desc = "Cycle to previous buffer"; + }; + } + ])); + }; }