From a7cdfaa32585fce404cf8890bae099348e53e0ad Mon Sep 17 00:00:00 2001 From: Johannes Rosenberger Date: Sat, 25 Apr 2020 17:02:49 +0200 Subject: [PATCH] tmux: reorder tmux.conf content In particular, put `extraConfig` in the end, which enables overriding of all settings, even plugin settings. PR #945 --- modules/programs/tmux.nix | 94 +++++++++---------- .../tmux/disable-confirmation-prompt.conf | 1 - .../programs/tmux/emacs-with-plugins.conf | 3 +- tests/modules/programs/tmux/vi-all-true.conf | 1 - 4 files changed, 46 insertions(+), 53 deletions(-) diff --git a/modules/programs/tmux.nix b/modules/programs/tmux.nix index 0841751a9..b3aa53bca 100644 --- a/modules/programs/tmux.nix +++ b/modules/programs/tmux.nix @@ -31,6 +31,13 @@ let boolToStr = value: if value then "on" else "off"; tmuxConf = '' + ${optionalString cfg.sensibleOnTop '' + # ============================================= # + # Start with defaults from the Sensible plugin # + # --------------------------------------------- # + run-shell ${pkgs.tmuxPlugins.sensible.rtp} + # ============================================= # + ''} set -g default-terminal "${cfg.terminal}" set -g base-index ${toString cfg.baseIndex} setw -g pane-base-index ${toString cfg.baseIndex} @@ -74,10 +81,40 @@ let setw -g clock-mode-style ${if cfg.clock24 then "24" else "12"} set -s escape-time ${toString cfg.escapeTime} set -g history-limit ${toString cfg.historyLimit} - - ${cfg.extraConfig} ''; + configPlugins = { + assertions = [( + let + hasBadPluginName = p: !(hasPrefix "tmuxplugin" (pluginName p)); + badPlugins = filter hasBadPluginName cfg.plugins; + in + { + assertion = badPlugins == []; + message = + "Invalid tmux plugin (not prefixed with \"tmuxplugins\"): " + + concatMapStringsSep ", " pluginName badPlugins; + } + )]; + + home.file.".tmux.conf".text = '' + # ============================================= # + # Load plugins with Home Manager # + # --------------------------------------------- # + + ${(concatMapStringsSep "\n\n" (p: '' + # ${pluginName p} + # --------------------- + ${p.extraConfig or ""} + run-shell ${ + if types.package.check p + then p.rtp + else p.plugin.rtp + } + '') cfg.plugins)} + # ============================================= # + ''; + }; in { @@ -258,63 +295,22 @@ in }; config = mkIf cfg.enable ( - mkMerge [ + mkMerge ([ { home.packages = [ cfg.package ] ++ optional cfg.tmuxinator.enable pkgs.tmuxinator ++ optional cfg.tmuxp.enable pkgs.tmuxp; - - home.file.".tmux.conf".text = tmuxConf; } - - (mkIf cfg.sensibleOnTop { - home.file.".tmux.conf".text = mkBefore '' - # ============================================= # - # Start with defaults from the Sensible plugin # - # --------------------------------------------- # - run-shell ${pkgs.tmuxPlugins.sensible.rtp} - # ============================================= # - ''; - }) - (mkIf cfg.secureSocket { home.sessionVariables = { TMUX_TMPDIR = ''''${XDG_RUNTIME_DIR:-"/run/user/\$(id -u)"}''; }; }) - (mkIf (cfg.plugins != []) { - assertions = [( - let - hasBadPluginName = p: !(hasPrefix "tmuxplugin" (pluginName p)); - badPlugins = filter hasBadPluginName cfg.plugins; - in - { - assertion = badPlugins == []; - message = - "Invalid tmux plugin (not prefixed with \"tmuxplugins\"): " - + concatMapStringsSep ", " pluginName badPlugins; - } - )]; - - home.file.".tmux.conf".text = mkAfter '' - # ============================================= # - # Load plugins with Home Manager # - # --------------------------------------------- # - - ${(concatMapStringsSep "\n\n" (p: '' - # ${pluginName p} - # --------------------- - ${p.extraConfig or ""} - run-shell ${ - if types.package.check p - then p.rtp - else p.plugin.rtp - } - '') cfg.plugins)} - # ============================================= # - ''; - }) - ] + # config file ~/.tmux.conf + { home.file.".tmux.conf".text = mkBefore tmuxConf; } + (mkIf (cfg.plugins != []) configPlugins) + { home.file.".tmux.conf".text = mkAfter cfg.extraConfig; } + ]) ); } diff --git a/tests/modules/programs/tmux/disable-confirmation-prompt.conf b/tests/modules/programs/tmux/disable-confirmation-prompt.conf index b599e603e..222f733d5 100644 --- a/tests/modules/programs/tmux/disable-confirmation-prompt.conf +++ b/tests/modules/programs/tmux/disable-confirmation-prompt.conf @@ -28,4 +28,3 @@ setw -g clock-mode-style 12 set -s escape-time 500 set -g history-limit 2000 - diff --git a/tests/modules/programs/tmux/emacs-with-plugins.conf b/tests/modules/programs/tmux/emacs-with-plugins.conf index 66b101837..97e226316 100644 --- a/tests/modules/programs/tmux/emacs-with-plugins.conf +++ b/tests/modules/programs/tmux/emacs-with-plugins.conf @@ -28,8 +28,6 @@ setw -g clock-mode-style 24 set -s escape-time 500 set -g history-limit 2000 - - # ============================================= # # Load plugins with Home Manager # # --------------------------------------------- # @@ -52,3 +50,4 @@ run-shell @tmuxplugin_prefix_highlight_rtp@ run-shell @tmuxplugin_fzf_tmux_url_rtp@ # ============================================= # + diff --git a/tests/modules/programs/tmux/vi-all-true.conf b/tests/modules/programs/tmux/vi-all-true.conf index 08e37e19b..de1cbe06e 100644 --- a/tests/modules/programs/tmux/vi-all-true.conf +++ b/tests/modules/programs/tmux/vi-all-true.conf @@ -28,4 +28,3 @@ setw -g clock-mode-style 24 set -s escape-time 500 set -g history-limit 2000 -