1
0

aerospace.nix 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. { pkgs, config, ... }:
  2. let
  3. cfg = config.services.aerospace;
  4. aerospace = "${pkgs.lib.meta.getExe cfg.package}";
  5. tmux = "${pkgs.lib.meta.getExe pkgs.tmux}";
  6. script = pkgs.writeShellScriptBin "aerospace-focus" ''
  7. direction="$1"
  8. if [[ -n "$(${aerospace} list-windows --focused | grep tmux)" ]]; then
  9. tmux_dir=""
  10. case "$direction" in
  11. left) tmux_dir="L" ;;
  12. down) tmux_dir="D" ;;
  13. up) tmux_dir="U" ;;
  14. right) tmux_dir="R" ;;
  15. esac
  16. if [[ -n "$tmux_dir" ]]; then
  17. ret=$(${tmux} run "#{at_edge} $tmux_dir")
  18. if [[ $ret -eq 1 ]]; then
  19. ${aerospace} focus "$direction"
  20. else
  21. ${tmux} select-pane "-$tmux_dir"
  22. fi
  23. fi
  24. fi
  25. ${aerospace} focus "$direction"
  26. '';
  27. aerospace-focus = "${pkgs.lib.meta.getExe script}";
  28. in
  29. {
  30. # TODO: this needs to go to the home-manager config
  31. environment.systemPackages = [ script ];
  32. services.aerospace = {
  33. enable = true;
  34. settings = {
  35. gaps = {
  36. inner.horizontal = 10;
  37. inner.vertical = 10;
  38. outer.left = 10;
  39. outer.bottom = 10;
  40. outer.top = 10;
  41. outer.right = 10;
  42. };
  43. mode.main.binding = {
  44. alt-1 = "workspace 1";
  45. alt-2 = "workspace 2";
  46. alt-3 = "workspace 3";
  47. alt-4 = "workspace 4";
  48. alt-5 = "workspace 5";
  49. alt-b = "workspace B"; # Browser
  50. alt-e = "workspace E"; # Finder
  51. alt-m = "workspace M"; # Mail
  52. alt-s = "workspace S"; # Signal
  53. alt-t = "workspace T"; # Terminal
  54. alt-v = "workspace V"; # Video
  55. # moving windows to workspaces
  56. alt-shift-1 = "move-node-to-workspace 1";
  57. alt-shift-2 = "move-node-to-workspace 2";
  58. alt-shift-3 = "move-node-to-workspace 3";
  59. alt-shift-4 = "move-node-to-workspace 4";
  60. alt-shift-5 = "move-node-to-workspace 5";
  61. alt-shift-b = "move-node-to-workspace B";
  62. alt-shift-e = "move-node-to-workspace E";
  63. alt-shift-t = "move-node-to-workspace T";
  64. alt-shift-m = "move-node-to-workspace M";
  65. alt-shift-s = "move-node-to-workspace S";
  66. alt-shift-v = "move-node-to-workspace V";
  67. alt-shift-f = "fullscreen";
  68. # focus between windows
  69. ctrl-h = "exec-and-forget ${aerospace-focus} left";
  70. ctrl-l = "exec-and-forget ${aerospace-focus} right";
  71. ctrl-k = "exec-and-forget ${aerospace-focus} up";
  72. ctrl-j = "exec-and-forget ${aerospace-focus} down";
  73. # move between windows
  74. ctrl-shift-h = "move left";
  75. ctrl-shift-l = "move right";
  76. ctrl-shift-k = "move up";
  77. ctrl-shift-j = "move down";
  78. alt-shift-minus = "resize smart -50";
  79. alt-shift-equal = "resize smart +50";
  80. alt-tab = "workspace-back-and-forth";
  81. alt-shift-tab = "move-workspace-to-monitor --wrap-around next";
  82. alt-shift-semicolon = "mode service";
  83. alt-slash = "layout tiles horizontal vertical";
  84. alt-comma = "layout accordion horizontal vertical";
  85. };
  86. mode.service.binding = {
  87. esc = ["reload-config" "mode main"];
  88. r = ["flatten-workspace-tree" "mode main"];
  89. f = ["layout floating tiling" "mode main"];
  90. backspace = ["close-all-windows-but-current" "mode main"];
  91. alt-shift-h = ["join-with left" "mode main"];
  92. alt-shift-j = ["join-with down" "mode main"];
  93. alt-shift-k = ["join-with up" "mode main"];
  94. alt-shift-l = ["join-with right" "mode main"];
  95. };
  96. on-window-detected = [
  97. {
  98. "if".app-id = "org.whispersystems.signal-desktop";
  99. check-further-callbacks = false;
  100. run = [ "move-node-to-workspace S" ];
  101. }
  102. {
  103. "if".app-id = "com.apple.finder";
  104. check-further-callbacks = false;
  105. run = [ "move-node-to-workspace E" ];
  106. }
  107. {
  108. "if".app-id = "com.apple.mail";
  109. check-further-callbacks = false;
  110. run = [ "move-node-to-workspace M" ];
  111. }
  112. {
  113. "if".app-id = "com.mitchellh.ghostty";
  114. check-further-callbacks = false;
  115. run = [ "move-node-to-workspace T" ];
  116. }
  117. ];
  118. };
  119. };
  120. }