.dotfiles/home/.tmux.conf
Martin Larsson bcec4985b2 Change tmux to support 256 colors in Ghostty and Tmux for NixOS, WSL2
(NixOS), Mac, and Asahi Fedora Remix (should in theory just work
everywhere that runs Ghostty and Tmux now)
2025-01-02 11:46:49 +01:00

111 lines
4.4 KiB
Bash

# For some reason, fzf is missing from path when running shell scripts through tmux keybindings
set-environment -g PATH "~/dev/git/fzf/bin:$PATH"
# Keybindings for navigating between panes
bind-key -n M-Left select-pane -L
bind-key -n M-Down select-pane -D
bind-key -n M-Up select-pane -U
bind-key -n M-Right select-pane -R
# Resize mode
set -g @tmux_resize_mode 0
set -g @resize_mode_path "~/.config/tmux/tmux-set-resize-mode.sh"
bind-key -n M-Space if-shell -F "#{==:#{@tmux_resize_mode},0}" "run-shell '#{@resize_mode_path} 1'" ""
bind-key -n Escape if-shell -F "#{==:#{@tmux_resize_mode},1}" "run-shell '#{@resize_mode_path} 0'" "send-keys Escape"
bind-key -n Enter if-shell -F "#{==:#{@tmux_resize_mode},1}" "run-shell '#{@resize_mode_path} 0'" "send-keys Enter"
bind-key -n q if-shell -F "#{==:#{@tmux_resize_mode},1}" "run-shell '#{@resize_mode_path} 0'" "send-keys q"
# Resize the panes if we are in resize mode
bind-key -n Up if -F "#{==:#{@tmux_resize_mode},1}" "resize-pane -U" "send-keys Up"
bind-key -n Down if -F "#{==:#{@tmux_resize_mode},1}" "resize-pane -D" "send-keys Down"
bind-key -n Left if -F "#{==:#{@tmux_resize_mode},1}" "resize-pane -L" "send-keys Left"
bind-key -n Right if -F "#{==:#{@tmux_resize_mode},1}" "resize-pane -R" "send-keys Right"
bind-key -n M-p display-message "#{@tmux_resize_mode}"
bind-key -n M-d run-shell "~/.config/tmux/tmux-fuzzy-find-session.sh"
# Split window, change keybindings to match vim concept of splits
bind-key -n M-v split-window -h
bind-key -n M-h split-window -v
bind-key -n M-q kill-pane
bind-key -n M-f resize-pane -Z
bind-key -n M-s command-prompt -p "New session: " "run-shell '~/.config/tmux/tmux-create-session.sh '%%''"
bind-key -n M-w new-window
bind-key -n M-r command-prompt -p "Rename window:" "rename-window '%%'"
bind-key -n M-R command-prompt -p "Rename session:" "rename-session '%%'"
bind-key -n M-c copy-mode
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
bind-key -n M-0 select-window -t 0
bind-key -n M-1 select-window -t 1
bind-key -n M-2 select-window -t 2
bind-key -n M-3 select-window -t 3
bind-key -n M-4 select-window -t 4
bind-key -n M-5 select-window -t 5
bind-key -n M-6 select-window -t 6
bind-key -n M-7 select-window -t 7
bind-key -n M-8 select-window -t 8
bind-key -n M-9 select-window -t 9
set -g @move-pane-path "~/.config/tmux/tmux-move-pane.sh"
bind-key -n M-) run-shell "#{@move-pane-path} 0"
bind-key -n M-! run-shell "#{@move-pane-path} 1"
bind-key -n M-@ run-shell "#{@move-pane-path} 2"
bind-key -n M-# run-shell "#{@move-pane-path} 3"
bind-key -n M-$ run-shell "#{@move-pane-path} 4"
bind-key -n M-% run-shell "#{@move-pane-path} 5"
bind-key -n M-^ run-shell "#{@move-pane-path} 6"
bind-key -n M-& run-shell "#{@move-pane-path} 7"
bind-key -n M-* run-shell "#{@move-pane-path} 8"
bind-key -n M-( run-shell "#{@move-pane-path} 9"
# Reload tmux configuration
bind-key -n M-C source-file ~/.tmux.conf \; display-message "Config reloaded"
# Set the default terminal to support 256 colors
set -g default-terminal "tmux-256color"
# Enable true color support in tmux
set-option -ga terminal-features ',xterm-ghostty:RGB'
set-option -ga terminal-features ',xterm-256color:RGB'
set-option -ga terminal-features ',tmux-256color:RGB'
# Ensure tmux recognizes terminal overrides for true color
set-option -ga terminal-overrides ',xterm-ghostty:Tc'
set-option -ga terminal-overrides ',xterm-256color:Tc'
set-option -ga terminal-overrides ',*:Tc'
# Specific overrides for underline and underline colors (requires tmux >= 3.0)
set -as terminal-overrides ',*:Smulx=\E[4::%p1%dm'
set -as terminal-overrides ',*:Setulc=\E[58::2::::%p1%{65536}%/%d::%p1%{256}%/%{255}%&%d::%p1%{255}%&%d%;m'
# Set the default terminal to support 256 colors
# set -g default-terminal "xterm-ghostty"
# Ensure tmux uses true color
# set-option -ga terminal-features 'xterm-256color:RGB'
# set-option -ga terminal-overrides ',xterm-256color:Tc'
# set-option -ga terminal-features 'xterm-ghostty:RGB'
# set-option -ga terminal-overrides ',xterm-ghostty:Tc'
# Make sure that the index of windows and panes starts at 1
set -g base-index 1
set -g pane-base-index 1
set -g renumber-windows on
set -g mode-keys vi
set -g history-limit 10000
set-option -g status-position top
set -g @catppuccin_flavour "macchiato"
set -g @catppuccin_status_background "#1e2030"
set -g @plugin "catppuccin/tmux"
set -g @plugin "tmux-plugins/tmux-sensible"
set -g @plugin "tmux-plugins/tpm"
run "~/dev/git/tpm/tpm"