diff options
author | toonn <toonn@toonn.io> | 2020-05-20 15:23:00 +0200 |
---|---|---|
committer | Robert Helgesson <robert@rycee.net> | 2020-12-21 00:10:59 +0100 |
commit | a1162e04b3c1b9cdc8a10e3cfcbe6dcf5dcd002f (patch) | |
tree | 4007eed7cd18d73f4fda54e8c095f4733cf726f0 | |
parent | e87bccabc318475ab712470657b85435354b53f7 (diff) |
tmux: add a prefix option overruling shortcut if defined
Previously, it was not possible to set an arbitrary tmux prefix since
CTRL was hardcoded in the module.
To avoid breaking existing configs, a new option was implemented that
conveniently uses the tmux terminology but defaults to null and does
not affect previous behavior when set to null.
The behavior for the shortcut option was not completely replicated,
i.e., it does not bind "b" to send-prefix but stick to the default of
the prefix binding sending prefix (C-b C-b instead of C-b b) and it
does not bind repetition of the prefix (C-b C-b) to `last-window`,
both of these bring the option closer to the default tmux
configuration.
Fixes #1237
-rw-r--r-- | modules/programs/tmux.nix | 31 | ||||
-rw-r--r-- | tests/modules/programs/tmux/default.nix | 2 | ||||
-rw-r--r-- | tests/modules/programs/tmux/prefix.conf | 32 | ||||
-rw-r--r-- | tests/modules/programs/tmux/prefix.nix | 26 | ||||
-rw-r--r-- | tests/modules/programs/tmux/shortcut-without-prefix.conf | 33 | ||||
-rw-r--r-- | tests/modules/programs/tmux/shortcut-without-prefix.nix | 27 |
6 files changed, 144 insertions, 7 deletions
diff --git a/modules/programs/tmux.nix b/modules/programs/tmux.nix index e28145da125b..295df490a362 100644 --- a/modules/programs/tmux.nix +++ b/modules/programs/tmux.nix @@ -68,13 +68,21 @@ let bind -r L resize-pane -R ${toString cfg.resizeAmount} ''} - ${optionalString (cfg.shortcut != defaultShortcut) '' - # rebind main key: C-${cfg.shortcut} - unbind C-${defaultShortcut} - set -g prefix C-${cfg.shortcut} - bind ${cfg.shortcut} send-prefix - bind C-${cfg.shortcut} last-window - ''} + ${if cfg.prefix != null + then '' + # rebind main key: ${cfg.prefix} + unbind C-${defaultShortcut} + set -g prefix ${cfg.prefix} + bind ${cfg.prefix} send-prefix + '' + else optionalString (cfg.shortcut != defaultShortcut) '' + # rebind main key: C-${cfg.shortcut} + unbind C-${defaultShortcut} + set -g prefix C-${cfg.shortcut} + bind ${cfg.shortcut} send-prefix + bind C-${cfg.shortcut} last-window + '' + } ${optionalString cfg.disableConfirmationPrompt '' bind-key & kill-window @@ -238,6 +246,15 @@ in ''; }; + prefix = mkOption { + default = null; + example = "C-a"; + type = types.nullOr types.str; + description = '' + Set the prefix key. Overrules the "shortcut" option when set. + ''; + }; + shortcut = mkOption { default = defaultShortcut; example = "a"; diff --git a/tests/modules/programs/tmux/default.nix b/tests/modules/programs/tmux/default.nix index f0a997b7e730..be78c2620a4a 100644 --- a/tests/modules/programs/tmux/default.nix +++ b/tests/modules/programs/tmux/default.nix @@ -5,4 +5,6 @@ tmux-secure-socket-enabled = ./secure-socket-enabled.nix; tmux-disable-confirmation-prompt = ./disable-confirmation-prompt.nix; tmux-default-shell = ./default-shell.nix; + tmux-shortcut-without-prefix = ./shortcut-without-prefix.nix; + tmux-prefix = ./prefix.nix; } diff --git a/tests/modules/programs/tmux/prefix.conf b/tests/modules/programs/tmux/prefix.conf new file mode 100644 index 000000000000..318803002366 --- /dev/null +++ b/tests/modules/programs/tmux/prefix.conf @@ -0,0 +1,32 @@ +# ============================================= # +# Start with defaults from the Sensible plugin # +# --------------------------------------------- # +run-shell @sensible_rtp@ +# ============================================= # + +set -g default-terminal "screen" +set -g base-index 0 +setw -g pane-base-index 0 + + + + + +set -g status-keys emacs +set -g mode-keys emacs + + + +# rebind main key: C-a +unbind C-b +set -g prefix C-a +bind C-a send-prefix + + + + +setw -g aggressive-resize off +setw -g clock-mode-style 12 +set -s escape-time 500 +set -g history-limit 2000 + diff --git a/tests/modules/programs/tmux/prefix.nix b/tests/modules/programs/tmux/prefix.nix new file mode 100644 index 000000000000..80ed6964075c --- /dev/null +++ b/tests/modules/programs/tmux/prefix.nix @@ -0,0 +1,26 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.tmux = { + enable = true; + prefix = "C-a"; + }; + + nixpkgs.overlays = [ + (self: super: { + tmuxPlugins = super.tmuxPlugins // { + sensible = super.tmuxPlugins.sensible // { rtp = "@sensible_rtp@"; }; + }; + }) + ]; + + nmt.script = '' + assertFileExists home-files/.tmux.conf + assertFileContent home-files/.tmux.conf \ + ${./prefix.conf} + ''; + }; +} diff --git a/tests/modules/programs/tmux/shortcut-without-prefix.conf b/tests/modules/programs/tmux/shortcut-without-prefix.conf new file mode 100644 index 000000000000..a8bc59cbb83a --- /dev/null +++ b/tests/modules/programs/tmux/shortcut-without-prefix.conf @@ -0,0 +1,33 @@ +# ============================================= # +# Start with defaults from the Sensible plugin # +# --------------------------------------------- # +run-shell @sensible_rtp@ +# ============================================= # + +set -g default-terminal "screen" +set -g base-index 0 +setw -g pane-base-index 0 + + + + + +set -g status-keys emacs +set -g mode-keys emacs + + + +# rebind main key: C-a +unbind C-b +set -g prefix C-a +bind a send-prefix +bind C-a last-window + + + + +setw -g aggressive-resize off +setw -g clock-mode-style 12 +set -s escape-time 500 +set -g history-limit 2000 + diff --git a/tests/modules/programs/tmux/shortcut-without-prefix.nix b/tests/modules/programs/tmux/shortcut-without-prefix.nix new file mode 100644 index 000000000000..52290c4fc42b --- /dev/null +++ b/tests/modules/programs/tmux/shortcut-without-prefix.nix @@ -0,0 +1,27 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.tmux = { + enable = true; + shortcut = "a"; + prefix = null; + }; + + nixpkgs.overlays = [ + (self: super: { + tmuxPlugins = super.tmuxPlugins // { + sensible = super.tmuxPlugins.sensible // { rtp = "@sensible_rtp@"; }; + }; + }) + ]; + + nmt.script = '' + assertFileExists home-files/.tmux.conf + assertFileContent home-files/.tmux.conf \ + ${./shortcut-without-prefix.conf} + ''; + }; +} |