nix/modules/home-manager/cli/tmux/default.nix
2025-05-12 09:04:21 +02:00

94 lines
3.9 KiB
Nix

{ lib, config, pkgs, ... }:
with lib;
let
cfg = config.modules.cli.tmux;
in
{
options.modules.cli.tmux = {
enable = mkEnableOption "enable Tmux";
extraConfig = mkOption {
type = types.lines;
default = '''';
description = ''
user related Tmux options, wee be concatenated with options defined
in the module.
'';
};
};
config = mkIf cfg.enable {
home.file.".local/bin/create-tmux-session".source = ./files/create-tmux-session.sh;
programs.tmux = {
enable = true;
aggressiveResize = true;
baseIndex = 1;
customPaneNavigationAndResize = false;
escapeTime = 0;
focusEvents = true;
keyMode = "vi";
mouse = true;
prefix = "C-a";
terminal = "tmux-256color";
extraConfig = ''
set -g detach-on-destroy off
set -g display-time 1500
bind -n -N "Select pane to the left of the active pane" M-h select-pane -L
bind -n -N "Select pane below the active pane" M-j select-pane -D
bind -n -N "Select pane above the active pane" M-k select-pane -U
bind -n -N "Select pane to the right of the active pane" M-l select-pane -R
bind -n -r -N "Resize the pane left by 5" M-H resize-pane -L 5
bind -n -r -N "Resize the pane down by 5" M-J resize-pane -D 5
bind -n -r -N "Resize the pane up by 5" M-K resize-pane -U 5
bind -n -r -N "Resize the pane right by 5" M-L resize-pane -R 5
bind -n M-n split-window -h -c "#{pane_current_path}"
bind -n M-N split-window -v -c "#{pane_current_path}"
# define sessions with Alt+F{1..4} for general purpose sessions
bind -n M-F1 if 'tmux has-session -t 1' {switch-client -t 1} {display-popup -E -E 'create-tmux-session -i 1'}
bind -n M-F2 if 'tmux has-session -t 2' {switch-client -t 2} {display-popup -E -E 'create-tmux-session -i 2'}
bind -n M-F3 if 'tmux has-session -t 3' {switch-client -t 3} {display-popup -E -E 'create-tmux-session -i 3'}
bind -n M-F4 if 'tmux has-session -t 4' {switch-client -t 4} {display-popup -E -E 'create-tmux-session -i 4'}
# Alt+F10 for launching my Nix project
bind -n M-F10 run 'create-tmux-session -n config -r nix "run:nvim ." vsplit:20'
# change window with Alt+{1..5}
bind -n -N "Goto window 1" M-1 select-window -T -t 1
bind -n -N "Goto window 2" M-2 select-window -T -t 2
bind -n -N "Goto window 3" M-3 select-window -T -t 3
bind -n -N "Goto window 4" M-4 select-window -T -t 4
bind -n -N "Goto window 5" M-5 select-window -T -t 5
# Theme
set -g status-interval 2
setw -g automatic-rename on # rename window to reflect current program
set -g renumber-windows on # renumber windows when a window is closed
set -g set-titles on
set -g mode-style bg=colour18,fg=colour7
set -g set-titles-string "#T"
set -g status-bg colour0
set -g status-fg colour7
set -g message-style bg=colour19,fg=colour7
setw -g window-status-current-format '#[fg=colour18,bg=colour11] #I\
#[bg=colour19,fg=colour7,bold] #W\
#{?window_active,󰎂 ,}#{?window_marked_flag,󰃃 ,}#{?window_activity_flag, ,}#{?window_silence_flag,󰝟 ,}#{?window_zoomed_flag,󱀅 ,}#{?window_bell_flag,#[fg=colour1]󱈸 ,}'
set -g pane-border-style fg=colour19
set -g pane-active-border-style fg=colour4
setw -g window-status-format '#[bg=color12,fg=colour19] #I\
#[bg=colour18,fg=colour7,dim] #W\
#{?window_last_flag, ,}#{?window_marked_flag,󰃃 ,}#{?window_activity_flag, ,}#{?window_silence_flag,󰝟 ,}#{?window_zoomed_flag,󱀅 ,}#{?window_bell_flag,#[fg=colour1]󱈸 ,}'
set -g status-left-length 100
set -g status-left '#[bg=colour0, fg=colour6] #S '
set -g status-right ' '
'' + cfg.extraConfig;
plugins = with pkgs; [
tmuxPlugins.tmux-fzf
];
};
};
}