From 761102fd35b3f0bc4db1f439455b17e90e8598dd Mon Sep 17 00:00:00 2001 From: hektor Date: Mon, 28 Sep 2026 20:50:04 +0200 Subject: [PATCH] refactor(tmux): nixify configuration --- dots/.config/tmux/tmux.conf | 80 ----------------------------------- home/modules/tmux/default.nix | 79 +++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 82 deletions(-) delete mode 100644 dots/.config/tmux/tmux.conf diff --git a/dots/.config/tmux/tmux.conf b/dots/.config/tmux/tmux.conf deleted file mode 100644 index 1c68e05..0000000 --- a/dots/.config/tmux/tmux.conf +++ /dev/null @@ -1,80 +0,0 @@ -# statusbar -setw -g monitor-activity on -set -g visual-activity on -set -g history-limit 100000 -set -g default-command "${SHELL}" -setw -g aggressive-resize on -set -sg escape-time 0 - -# keybindings -# NOTE: I intend to use defaults whenever feasible -# - my prefix key is still C-b -# - however, I do use vi mode -setw -g mode-keys vi -set -g status-keys vi -bind r source-file ~/.config/tmux/tmux.conf # reload tmux conf -# Splits -unbind v -unbind s -unbind % # vsplit -unbind '"' # hsplit -bind v split-window -h -c "#{pane_current_path}" -bind s split-window -v -c "#{pane_current_path}" -bind -r h select-pane -L -bind -r j select-pane -D -bind -r k select-pane -U -bind -r l select-pane -R -bind -r H resize-pane -L 4 -bind -r J resize-pane -D 4 -bind -r K resize-pane -U 4 -bind -r L resize-pane -R 4 - -bind-key -T root F1 select-window -t 1 -bind-key -T root F2 select-window -t 2 -bind-key -T root F3 select-window -t 3 -bind-key -T root F4 select-window -t 4 -bind-key -T root F5 select-window -t 5 -bind-key -T root F6 select-window -t 6 -bind-key -T root F7 select-window -t 7 -bind-key -T root F8 select-window -t 8 -bind-key -T root F9 select-window -t 9 - - -# bind-key j command-prompt -p "join pane from:" "join-pane -s '%%'" -# bind-key s command-prompt -p "send pane to:" "join-pane -t '%%'" -bind-key -T root S-F1 join-pane -s :1 -bind-key -T root S-F2 join-pane -s :2 -bind-key -T root S-F3 join-pane -s :3 -bind-key -T root S-F4 join-pane -s :4 -bind-key -T root S-F5 join-pane -s :5 -bind-key -T root S-F6 join-pane -s :6 -bind-key -T root S-F7 join-pane -s :7 -bind-key -T root S-F8 join-pane -s :8 -bind-key -T root S-F9 join-pane -s :9 - -# 1-based indexing makes most sense for keyboard layouts (where number row start at 1) -set -g base-index 1 -set -g pane-base-index 1 - -# statusbar -set -g status-position top -set -g status-left-length 20 -set -g window-status-separator "" -%if "#{==:#{host},desktop-arch}" -set -g status-left "#[bg=colour235,fg=colour255] #S #[fg=colour235,bg=default] " -set -g status-right "" -%else -set -g status-left '#h ' -set -g status-right '#(uptime | cut -f 4-5 -d " " | cut -f 1 -d ",") %a %l:%M:%S %p %Y-%m-%d' -%endif - -set -g default-terminal "tmux-256color" - -# Vi copypaste mode -if-shell "test '\( #{$TMUX_VERSION_MAJOR} -eq 2 -a #{$TMUX_VERSION_MINOR} -ge 4 \)'" 'bind-key -Tcopy-mode-vi v send -X begin-selection; bind-key -Tcopy-mode-vi y send -X copy-selection-and-cancel' -if-shell '\( #{$TMUX_VERSION_MAJOR} -eq 2 -a #{$TMUX_VERSION_MINOR} -lt 4\) -o #{$TMUX_VERSION_MAJOR} -le 1' 'bind-key -t vi-copy v begin-selection; bind-key -t vi-copy y copy-selection' -if-shell '\( #{$TMUX_VERSION_MAJOR} -eq 2 -a #{$TMUX_VERSION_MINOR} -lt 2\) -o #{$TMUX_VERSION_MAJOR} -le 1' 'set-option -g status-utf8 on' - -set -g allow-passthrough on -set -s extended-keys on -set -as terminal-features 'xterm*:extkeys' diff --git a/home/modules/tmux/default.nix b/home/modules/tmux/default.nix index ddde283..969f726 100644 --- a/home/modules/tmux/default.nix +++ b/home/modules/tmux/default.nix @@ -2,7 +2,6 @@ config, lib, pkgs, - dotsPath, ... }: @@ -17,7 +16,83 @@ programs.tmux = { enable = true; - extraConfig = builtins.readFile (dotsPath + "/.config/tmux/tmux.conf"); + historyLimit = 100000; + aggressiveResize = true; + escapeTime = 0; + keyMode = "vi"; + # 1-based indexing makes most sense for keyboard layouts (where number row start at 1) + baseIndex = 1; + terminal = "tmux-256color"; + extraConfig = '' + # statusbar + setw -g monitor-activity on + set -g visual-activity on + set -g default-command "''${SHELL}" + + # keybindings + # NOTE: I intend to use defaults whenever feasible + # - my prefix key is still C-b + # - however, I do use vi mode + bind r source-file ~/.config/tmux/tmux.conf # reload tmux conf + # Splits + unbind v + unbind s + unbind % # vsplit + unbind '"' # hsplit + bind v split-window -h -c "#{pane_current_path}" + bind s split-window -v -c "#{pane_current_path}" + bind -r h select-pane -L + bind -r j select-pane -D + bind -r k select-pane -U + bind -r l select-pane -R + bind -r H resize-pane -L 4 + bind -r J resize-pane -D 4 + bind -r K resize-pane -U 4 + bind -r L resize-pane -R 4 + + bind-key -T root F1 select-window -t 1 + bind-key -T root F2 select-window -t 2 + bind-key -T root F3 select-window -t 3 + bind-key -T root F4 select-window -t 4 + bind-key -T root F5 select-window -t 5 + bind-key -T root F6 select-window -t 6 + bind-key -T root F7 select-window -t 7 + bind-key -T root F8 select-window -t 8 + bind-key -T root F9 select-window -t 9 + + # bind-key j command-prompt -p "join pane from:" "join-pane -s '%%'" + # bind-key s command-prompt -p "send pane to:" "join-pane -t '%%'" + bind-key -T root S-F1 join-pane -s :1 + bind-key -T root S-F2 join-pane -s :2 + bind-key -T root S-F3 join-pane -s :3 + bind-key -T root S-F4 join-pane -s :4 + bind-key -T root S-F5 join-pane -s :5 + bind-key -T root S-F6 join-pane -s :6 + bind-key -T root S-F7 join-pane -s :7 + bind-key -T root S-F8 join-pane -s :8 + bind-key -T root S-F9 join-pane -s :9 + + # statusbar + set -g status-position top + set -g status-left-length 20 + set -g window-status-separator "" + %if "#{==:#{host},desktop-arch}" + set -g status-left "#[bg=colour235,fg=colour255] #S #[fg=colour235,bg=default] " + set -g status-right "" + %else + set -g status-left '#h ' + set -g status-right '#(uptime | cut -f 4-5 -d " " | cut -f 1 -d ",") %a %l:%M:%S %p %Y-%m-%d' + %endif + + # Vi copypaste mode + if-shell "test '\( #{$TMUX_VERSION_MAJOR} -eq 2 -a #{$TMUX_VERSION_MINOR} -ge 4 \)'" 'bind-key -Tcopy-mode-vi v send -X begin-selection; bind-key -Tcopy-mode-vi y send -X copy-selection-and-cancel' + if-shell '\( #{$TMUX_VERSION_MAJOR} -eq 2 -a #{$TMUX_VERSION_MINOR} -lt 4\) -o #{$TMUX_VERSION_MAJOR} -le 1' 'bind-key -t vi-copy v begin-selection; bind-key -t vi-copy y copy-selection' + if-shell '\( #{$TMUX_VERSION_MAJOR} -eq 2 -a #{$TMUX_VERSION_MINOR} -lt 2\) -o #{$TMUX_VERSION_MAJOR} -le 1' 'set-option -g status-utf8 on' + + set -g allow-passthrough on + set -s extended-keys on + set -as terminal-features 'xterm*:extkeys' + ''; }; }; }