diff --git a/home/tmux/default.nix b/home/tmux/default.nix new file mode 100644 index 0000000..f54a1c5 --- /dev/null +++ b/home/tmux/default.nix @@ -0,0 +1,146 @@ +{ + pkgs, + config, + ... +}: let + tmux-navigate = pkgs.tmuxPlugins.mkTmuxPlugin { + pluginName = "tmux-navigate"; + version = "0.2.0"; + src = pkgs.fetchFromGitHub { + owner = "sunaku"; + repo = "tmux-navigate"; + rev = "0.2.0"; + hash = "sha256-PQR07Mh1FzuVwyPPN40L/rufjOfP+ssR2NEtCmLlxg0="; + }; + }; +in { + programs.tmux = { + enable = true; + + rose-pine = { + enable = true; + extraConfig = '' + set -g @rose_pine_host 'on' + set -g @rose_pine_directory 'on' + ''; + }; + + # terminal = "tmux-256color"; + + # Start window & pane numbering at 1. + baseIndex = 1; + + # Vi mode. + keyMode = "vi"; + customPaneNavigationAndResize = true; + mouse = true; + + # Auto-spawn a new session when attaching if none exist. + newSession = true; + + # Key used with Ctrl to make the prefix. + shortcut = "a"; + + plugins = with pkgs.tmuxPlugins; [ + { + plugin = resurrect; + extraConfig = '' + set -g @resurrect-capture-pane-contents 'on' + ''; + } + + { + plugin = continuum; + extraConfig = '' + set -g @continuum-restore 'on' + ''; + } + + { + plugin = tilish; + extraConfig = '' + # Don't enforce the layout. + set -g @tilish-enforce 'none' + + set -g @tilish-project "$HOME/hackin" + set -g @tilish-navigate 'on' + ''; + } + + tmux-navigate + + yank + + { + plugin = jump; + extraConfig = '' + set -g @jump-key 's' + ''; + } + + { + plugin = fingers; + extraConfig = '' + set -g @fingers-jump-key 's' + ''; + } + + { + plugin = tmux-floax; + extraConfig = '' + set -g @floax-bind 'i' + ''; + } + ]; + + extraConfig = '' + # Set repeat timeout so keys can be repeated without the prefix. + set -g repeat-time 1000 + + # Auto-renumber windows when one is deleted. + set -g renumber-windows 'on' + + set -ag terminal-overrides ",*:RGB" + + set -g status-position 'top' + + ### Keybindings ### + + # Easy reload config. + bind r source-file ${config.xdg.configHome}/tmux/tmux.conf \; display-message "Reloaded config" + + # Better split commands. + bind -N 'vsplit' | split-window -h -c "#{pane_current_path}" + bind -N 'vsplit' \\ split-window -h -c "#{pane_current_path}" + bind -N 'hsplit' - split-window -v -c "#{pane_current_path}" + unbind '"' + unbind % + + # Vi-like resizing. + bind -r -N 'Resize pane (left)' M-h resize-pane -L 5 + bind -r -N 'Resize pane (down)' M-j resize-pane -D 5 + bind -r -N 'Resize pane (up)' M-k resize-pane -U 5 + bind -r -N 'Resize pane (right)' M-l resize-pane -R 5 + + # Even out panes. + bind -N 'Evenly distribute panes' = select-layout -E + + # Swap panes. + bind -r -N 'Swap current pane with the next' H swap-pane -U + bind -r -N 'Swap current pane with the previous' L swap-pane -D + + # Window switching. + bind -N 'Previous window' Left previous-window + bind -N 'Next window' Right next-window + + # Vi copy mode. + unbind [ + bind -N 'Enter normal (copy) mode' Escape copy-mode + + bind -T copy-mode-vi ? command-prompt -p '?' 'send -X search-backward %1' + bind -T copy-mode-vi / command-prompt -p '/' 'send -X search-forward %1' + bind -T copy-mode-vi q send -X cancel + bind -T copy-mode-vi Escape if-shell -F '#{selection_present}' 'send -X clear-selection' 'send -X cancel' + ''; + }; +}