1
0

aerospace.nix 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. { pkgs, config, ... }:
  2. let
  3. cfg = config.programs.aerospace;
  4. aerospace = "${pkgs.lib.meta.getExe cfg.package}";
  5. tmux = "${pkgs.lib.meta.getExe config.programs.tmux.package}";
  6. aerospace-focus-pkg = 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 aerospace-focus-pkg}";
  28. in
  29. {
  30. home.packages = [ aerospace-focus-pkg ];
  31. launchd.agents.aerospace = {
  32. enable = true;
  33. config = {
  34. ProgramArguments = [
  35. "${cfg.package}/Applications/AeroSpace.app/Contents/MacOS/AeroSpace"
  36. "--started-at-login"
  37. ];
  38. KeepAlive = true;
  39. RunAtLoad = true;
  40. };
  41. };
  42. programs.aerospace = {
  43. enable = true;
  44. userSettings = {
  45. start-at-login = true;
  46. gaps = {
  47. inner.horizontal = 10;
  48. inner.vertical = 10;
  49. outer.left = 10;
  50. outer.bottom = 10;
  51. outer.top = 10;
  52. outer.right = 10;
  53. };
  54. mode.main.binding = {
  55. alt-1 = "workspace 1";
  56. alt-2 = "workspace 2";
  57. alt-3 = "workspace 3";
  58. alt-4 = "workspace 4";
  59. alt-5 = "workspace 5";
  60. alt-b = "workspace B"; # Browser
  61. alt-e = "workspace E"; # Finder
  62. alt-m = "workspace M"; # Mail
  63. alt-n = "workspace N"; # Notes
  64. alt-s = "workspace S"; # Signal
  65. alt-t = "workspace T"; # Terminal
  66. alt-v = "workspace V"; # Video
  67. # moving windows to workspaces
  68. alt-shift-1 = "move-node-to-workspace 1";
  69. alt-shift-2 = "move-node-to-workspace 2";
  70. alt-shift-3 = "move-node-to-workspace 3";
  71. alt-shift-4 = "move-node-to-workspace 4";
  72. alt-shift-5 = "move-node-to-workspace 5";
  73. alt-shift-b = "move-node-to-workspace B";
  74. alt-shift-e = "move-node-to-workspace E";
  75. alt-shift-t = "move-node-to-workspace T";
  76. alt-shift-m = "move-node-to-workspace M";
  77. alt-shift-n = "move-node-to-workspace N";
  78. alt-shift-s = "move-node-to-workspace S";
  79. alt-shift-v = "move-node-to-workspace V";
  80. alt-shift-f = "fullscreen";
  81. # focus between windows
  82. ctrl-h = "exec-and-forget ${aerospace-focus} left";
  83. ctrl-l = "exec-and-forget ${aerospace-focus} right";
  84. ctrl-k = "exec-and-forget ${aerospace-focus} up";
  85. ctrl-j = "exec-and-forget ${aerospace-focus} down";
  86. # move between windows
  87. ctrl-shift-h = "move left";
  88. ctrl-shift-l = "move right";
  89. ctrl-shift-k = "move up";
  90. ctrl-shift-j = "move down";
  91. alt-shift-minus = "resize smart -50";
  92. alt-shift-equal = "resize smart +50";
  93. alt-tab = "workspace-back-and-forth";
  94. alt-shift-tab = "move-workspace-to-monitor --wrap-around next";
  95. alt-shift-semicolon = "mode service";
  96. alt-slash = "layout tiles horizontal vertical";
  97. alt-comma = "layout accordion horizontal vertical";
  98. };
  99. mode.service.binding = {
  100. esc = [
  101. "reload-config"
  102. "mode main"
  103. ];
  104. r = [
  105. "flatten-workspace-tree"
  106. "mode main"
  107. ];
  108. f = [
  109. "layout floating tiling"
  110. "mode main"
  111. ];
  112. backspace = [
  113. "close-all-windows-but-current"
  114. "mode main"
  115. ];
  116. alt-shift-h = [
  117. "join-with left"
  118. "mode main"
  119. ];
  120. alt-shift-j = [
  121. "join-with down"
  122. "mode main"
  123. ];
  124. alt-shift-k = [
  125. "join-with up"
  126. "mode main"
  127. ];
  128. alt-shift-l = [
  129. "join-with right"
  130. "mode main"
  131. ];
  132. };
  133. on-window-detected = [
  134. {
  135. "if".app-id = "org.whispersystems.signal-desktop";
  136. check-further-callbacks = false;
  137. run = [ "move-node-to-workspace S" ];
  138. }
  139. {
  140. "if".app-id = "com.apple.finder";
  141. check-further-callbacks = false;
  142. run = [ "move-node-to-workspace E" ];
  143. }
  144. {
  145. "if".app-id = "com.apple.mail";
  146. check-further-callbacks = false;
  147. run = [ "move-node-to-workspace M" ];
  148. }
  149. {
  150. "if".app-id = "com.mitchellh.ghostty";
  151. check-further-callbacks = false;
  152. run = [ "move-node-to-workspace T" ];
  153. }
  154. ];
  155. };
  156. };
  157. }