nix-config/modules/home-manager/tmux/default.nix

91 lines
3.9 KiB
Nix

{ config, pkgs, ... }:
let
tmux = "${pkgs.tmux}/bin/tmux";
ps = "${pkgs.procps}/bin/ps";
grep = "${pkgs.gnugrep}/bin/grep";
in {
programs.tmux = {
enable = true;
clock24 = true;
keyMode = "vi";
prefix = "C-b";
shell = "${pkgs.zsh}/bin/zsh";
extraConfig = ''
set -g default-terminal "tmux-256color"
# set-option -sa terminal-overrides ',alacritty:Tc'
is_vim="${ps} -o state= -o comm= -t '#{pane_tty}' \
| ${grep} -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind -n 'M-h' if-shell "$is_vim" 'send-keys M-h' 'select-pane -L'
bind -n 'M-j' if-shell "$is_vim" 'send-keys M-j' 'select-pane -D'
bind -n 'M-k' if-shell "$is_vim" 'send-keys M-k' 'select-pane -U'
bind -n 'M-l' if-shell "$is_vim" 'send-keys M-l' 'select-pane -R'
bind-key -T copy-mode-vi 'C-h' select-pane -L
bind-key -T copy-mode-vi 'C-j' select-pane -D
bind-key -T copy-mode-vi 'C-k' select-pane -U
bind-key -T copy-mode-vi 'C-l' select-pane -R
bind -n 'M-1' 'select-window -t 1'
bind -n 'M-2' 'select-window -t 2'
bind -n 'M-3' 'select-window -t 3'
bind -n 'M-4' 'select-window -t 4'
bind -n 'M-5' 'select-window -t 5'
bind -n 'M-6' 'select-window -t 6'
bind -n 'M-7' 'select-window -t 7'
bind -n 'M-8' 'select-window -t 8'
bind -n 'M-9' 'select-window -t 9'
bind -n M-p select-window -p
bind -n M-n select-window -n
bind u \
capture-pane \; \
save-buffer /tmp/tmux-buffer \; \
run-shell 'sh -c "openurl /tmp/tmux-buffer"'
set -g base-index 1
setw -g pane-base-index 1
unbind p
bind-key -T copy-mode-vi y \
send-keys -X copy-pipe-and-cancel "xsel -i -p && xsel -o -p | xsel -i -b"
bind-key p run "xsel -o | ${tmux} load-buffer - ; ${tmux} paste-buffer"
bind c new-window -c "#{pane_current_path}"
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
set-option -g automatic-rename on
set -g mouse on
set -sg escape-time 0
set -g status-left-length 32
set -g status-right-length 150
set -g status-fg '#ebdbb2'
set -g status-bg '#282828'
setw -g window-status-separator ' '
set -g status-left '#[bg=#ebdbb2,fg=#282828,bold] #S #[bg=#282828] '
#set -g window-status-format "#[fg=#ebdbb2,bg=#a89974] #I #[fg=#a89974,bg=#282828]#[fg=#a89974,bg=#282828] #W "
set -g window-status-format "#[fg=#ebdbb2,bg=#a89974] #I #[fg=#a89974,bg=#282828]#[fg=#a89974,bg=#282828] #W "
#set -g window-status-current-format "#[fg=#fbf1c7,bg=#458588,noreverse,bold] #I #[fg=#458588,bg=#282828]#[fg=#fbf1c7,bg=#282828,noreverse,bold] #W "
set -g window-status-current-format "#[fg=#fbf1c7,bg=#458588,noreverse,bold] #I #[fg=#458588,bg=#282828]#[fg=#fbf1c7,bg=#282828,noreverse,bold] #W "
set -g status-right \'\'
set-hook -g 'session-created' 'run-shell -b "if [ \#{session_windows} -eq 1 ]; then ${tmux} set status off; else ${tmux} set status on; fi"'
set-hook -g 'after-new-window' 'run-shell -b "if [ \#{session_windows} -eq 1 ]; then ${tmux} set status off; else ${tmux} set status on; fi; if [ \#{window_panes} -eq 1 ]; then ${tmux} set pane-border-status off; fi"'
set-hook -g 'after-kill-pane' 'run-shell -b "if [ \#{session_windows} -eq 1 ]; then ${tmux} set status off; else ${tmux} set status on; fi; if [ \#{window_panes} -eq 1 ]; then ${tmux} set pane-border-status off; fi"'
set-hook -g 'pane-exited' 'run-shell -b "if [ \#{session_windows} -eq 1 ]; then ${tmux} set status off; else ${tmux} set status on; fi; if [ \#{window_panes} -eq 1 ]; then ${tmux} set pane-border-status off; fi"'
set-hook -g 'after-split-window' 'run-shell -b "if [ \#{window_panes} -gt 1 ]; then ${tmux} set pane-border-status top; fi"'
set -g default-command ${pkgs.zsh}/bin/zsh
'';
};
}