summaryrefslogtreecommitdiffstats
path: root/common/commandline/tmux.nix
blob: ccb6ad0cd60659efe20b0e0a5cbd3b21f543583e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
inputs: {
  config,
  pkgs,
  ...
}: let
  # Thanks: https://github.com/DanielFGray/dotfiles/blob/master/tmux.remote.conf
  remoteConf = builtins.toFile "tmux.remote.conf" ''
    unbind C-q
    unbind q
    set-option -g prefix C-s
    bind s send-prefix
    bind C-s last-window
    set-option -g status-position top
  '';
in {
  programs.tmux = {
    enable = true;
    shortcut = "q";
    escapeTime = 10;
    keyMode = "vi";
    terminal = "tmux-256color";
    historyLimit = 50000;

    plugins = with pkgs.tmuxPlugins; [tmux-thumbs sensible urlview];

    extraConfig = with config.theme; ''
      bind-key R run-shell ' \
        tmux source-file /etc/tmux.conf > /dev/null; \
        tmux display-message "sourced /etc/tmux.conf"'

      if -F "$SSH_CONNECTION" "source-file '${remoteConf}'"

      set-option -g status-right ' #{prefix_highlight} "#{=21:pane_title}" %H:%M %d-%b-%y'
      set-option -g status-left-length 20
      set-option -g @prefix_highlight_fg '${colors.background}'
      set-option -g @prefix_highlight_bg '${colors.dominant}'

      # Add plugin here because it needs its configuration
      run-shell '${pkgs.tmuxPlugins.prefix-highlight}/share/tmux-plugins/prefix-highlight/prefix_highlight.tmux'

      # Tmux Thumbs
      set -g @thumbs-alphabet dvorak

      # Be faster switching windows
      bind C-n next-window
      bind C-p previous-window

      set-option -g set-titles on

      bind C-y run-shell ' \
        ${pkgs.tmux}/bin/tmux show-buffer > /dev/null 2>&1 \
        && ${pkgs.tmux}/bin/tmux show-buffer | ${pkgs.xsel}/bin/xsel -ib'

      # Force true colors
      set-option -ga terminal-overrides ",*:Tc"

      set-option -g mouse on
      set-option -g focus-events on

      # Stay in same directory when split
      bind % split-window -h -c "#{pane_current_path}"
      bind '"' split-window -v -c "#{pane_current_path}"

      # Update these environment variables when creating or attaching to a session
      set-option -g update-environment "SSH_AUTH_SOCK WINDOWID SSH_CONNECTION DISPLAY SWAYSOCK"

      # Colorscheme
      set-option -g status-style 'fg=${colors.dimForeground}, bg=${colors.background}'

      set-option -g window-status-current-style 'fg=${colors.dominant}'

      set-option -g pane-border-style 'fg=${colors.background}'
      set-option -g pane-active-border-style 'fg=${colors.dominant}'

      set-option -g message-style 'fg=${colors.background}, bg=${colors.dimForeground}'

      set-option -g mode-style    'fg=${colors.background}, bg=${colors.dominant}'

      set-option -g display-panes-active-colour '${colors.dominant}'
      set-option -g display-panes-colour '${colors.dimForeground}'

      set-option -g clock-mode-colour '${colors.dominant}'
    '';
  };
}