Skip to content

Commit

Permalink
tmux: reorder tmux.conf content
Browse files Browse the repository at this point in the history
In particular, put `extraConfig` in the end, which enables overriding
of all settings, even plugin settings.

PR #945
  • Loading branch information
jorsn authored and rycee committed Apr 27, 2020
1 parent a6037a9 commit a7cdfaa
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 53 deletions.
94 changes: 45 additions & 49 deletions modules/programs/tmux.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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

{
Expand Down Expand Up @@ -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; }
])
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ setw -g clock-mode-style 12
set -s escape-time 500
set -g history-limit 2000


3 changes: 1 addition & 2 deletions tests/modules/programs/tmux/emacs-with-plugins.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
# --------------------------------------------- #
Expand All @@ -52,3 +50,4 @@ run-shell @tmuxplugin_prefix_highlight_rtp@
run-shell @tmuxplugin_fzf_tmux_url_rtp@

# ============================================= #

1 change: 0 additions & 1 deletion tests/modules/programs/tmux/vi-all-true.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ setw -g clock-mode-style 24
set -s escape-time 500
set -g history-limit 2000


0 comments on commit a7cdfaa

Please sign in to comment.