summaryrefslogtreecommitdiff
path: root/modules/common/defaultGlobalKeys.nix
blob: fc3c669b669ccf433605bea1f030570604f1aad8 (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
{
  pkgs,
  tsunamiLib,
  ...
}: let
  inherit (tsunamiLib) scriptPath;
in {
  tsunami.scripts."split" = ''
    width=$(tmux display -p "#{pane_width}")
    height=$(tmux display -p "#{pane_height}")

    if (( $(echo "$width / $height > 2.5" | ${pkgs.bc}/bin/bc -l) )); then
      tmux split-window -h "$@"
    else
      tmux split-window -v "$@"
    fi
  '';

  tsunami.scripts."clean-sessions" = ''
    current="$(tmux display -p '#{session_name}')"

    tmux list-sessions -F '#{session_name}' | while read -r line; do
      if [[ "$line" != "$current" && "$line" =~ ^[[:digit:]]+$ ]]; then
        tmux kill-session -t "$line"
      fi
    done
  '';

  tsunami.keys.global = [
    {
      key = "C-w";
      exec = "kill-pane";
    }
    {
      key = "M-z";
      exec = "resize-pane -Z";
    }
    {
      key = "C-Enter";
      exec = ''run-shell "${scriptPath "split"} -c '#{?@default-path,#{@default-path},#{pane_current_path}}'"'';
    }
    {
      key = "C-t";
      exec = "new-window -c '#{?@default-path,#{@default-path},#{pane_current_path}}'";
    }
    {
      key = "C-Tab";
      exec = "next-window";
    }
    {
      key = "C-S-Tab";
      exec = "previous-window";
    }
  ];

  tsunami.confs."windows" = ''
    unbind -n MouseDown3Pane
    set -g allow-rename on
    set -g automatic-rename off
    set -g renumber-windows on
    set -g base-index 1

    set-hook -ag client-detached 'run-shell ${scriptPath "clean-sessions"}'
    set-hook -ag client-session-changed 'run-shell ${scriptPath "clean-sessions"}'
  '';
}