From b23382ee8e152e80f1b1fb56d665c5eb27b491a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Fri, 28 Apr 2023 08:11:44 +0200 Subject: [PATCH] feat(tmux): add keybinds option --- modules/profiles/base.nix | 13 +++++++++++++ modules/programs/tmux.nix | 28 ++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/modules/profiles/base.nix b/modules/profiles/base.nix index 6f2fb3f..e2d4b4b 100644 --- a/modules/profiles/base.nix +++ b/modules/profiles/base.nix @@ -64,6 +64,19 @@ in gpg.enable = true; navi.enable = true; tmux.enable = true; + tmux.keybinds = { + prefix = { + "-" = "split-window -v"; + "|" = "split-window -h"; + "C-l" = "send-keys C-l"; + "R" = "source-file $XDG_CONFIG_HOME/tmux/tmux.conf \\; display-message 'Reloaded tmux.conf'"; + }; + copy-mode-vi = { + "v" = "send -X begin-selection"; + "V" = "send -X select-line"; + "C-v" = "send -X rectangle-toggle"; + }; + }; }; }; diff --git a/modules/programs/tmux.nix b/modules/programs/tmux.nix index aba543a..00e91ed 100644 --- a/modules/programs/tmux.nix +++ b/modules/programs/tmux.nix @@ -9,7 +9,7 @@ let runtimeInputs = with pkgs; [ tmux findutils coreutils procps fd ]; text = '' #!/usr/bin/env bash - + options=$(fd -HIg '.git' ~/ --min-depth 1 --max-depth 5 --type d --prune --exec dirname {} | fzf --filter "''$*") if [[ -z $options ]]; then @@ -43,6 +43,22 @@ in options.my.programs.tmux = { enable = mkEnableOption "tmux"; autoAttach = mkEnableOption "autoAttach"; + keybinds = mkOption { + type = with types; attrsOf (attrsOf string); + default = { }; + description = "Keybinds for tmux"; + example = literalExample '' + { + prefix = { + "-" = "split-window -v"; + "|" = "split-window -h"; + }; + copy-mode-vi = { + "v" = "send -X begin-selection"; + }; + } + ''; + }; }; config = mkIf cfg.enable { @@ -64,6 +80,15 @@ in tmux-fzf yank ]; + extraConfig = + let + mkKeybind = table: mapAttrsToList (keybind: value: "bind-key -T ${table} '${keybind}' ${value}"); + keybinds = flatten (mapAttrsToList mkKeybind cfg.keybinds); + in + '' + # Keybinds + ${concatStringsSep "\n" keybinds} + ''; }; fzf.tmux.enableShellIntegration = true; fish.interactiveShellInit = @@ -80,7 +105,6 @@ in end end ''; - }; }; }