#
# Tmux
#

{ pkgs, ... }:

{
  programs = {
    tmux = {
      enable = true;
      terminal = "xterm-256color";
      newSession = false;
      keyMode = "vi";
      historyLimit = 10000;
      clock24 = true;
      shortcut = "h";
      baseIndex = 1;
      plugins = [ pkgs.tmuxPlugins.dracula ];
      extraConfig = ''
        set -g @dracula-plugins "cpu-usage ram-usage network-bandwidth time"
        set -g mouse on
        #set -g @dracula-show-powerline true
        
        # More friendly split pane
        bind-key s split-window -h
        bind-key v split-window -v
        unbind '"'
        unbind '%'
        
        # moving between windows with vim movement keys
        bind m select-pane -L
        bind n select-pane -D
        bind e select-pane -U
        bind i select-pane -R

        # moving between windows with vim movement keys
        bind -r C-m select-window -t :-
        bind -r C-i select-window -t :+
        
        # Vim style X clipboard integration↲
        bind-key -T copy-mode-vi 'v' send -X begin-selection
        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"
        
        # resize panes with vim movement keys
        bind -r M resize-pane -L 5
        bind -r N resize-pane -D 5
        bind -r E resize-pane -U 5
        bind -r I resize-pane -R 5
        
        # bindings for pane joining and breaking
        bind < split-window -h \; choose-window 'kill-pane ; join-pane -hs %%'
        bind > break-pane -d
      '';
    };
  };
}