From f60254115a1e95845baad6e9be06a91889353920 Mon Sep 17 00:00:00 2001 From: sudosubin Date: Sun, 15 Dec 2024 20:12:48 +0900 Subject: [PATCH] feat: Use hammerspoon instead of skhd --- libraries/home-manager/default.nix | 1 - .../home-manager/programs/skhd/default.nix | 52 ---------- modules/darwin/home.nix | 1 - .../darwin/programs/hammerspoon/default.nix | 6 +- .../programs/hammerspoon/files/init.lua | 97 +++++++++++++++++++ modules/darwin/programs/skhd/default.nix | 77 --------------- modules/shared/programs/wezterm/default.nix | 2 +- 7 files changed, 103 insertions(+), 133 deletions(-) delete mode 100644 libraries/home-manager/programs/skhd/default.nix create mode 100644 modules/darwin/programs/hammerspoon/files/init.lua delete mode 100644 modules/darwin/programs/skhd/default.nix diff --git a/libraries/home-manager/default.nix b/libraries/home-manager/default.nix index 04b72c53..b9d1cdb3 100644 --- a/libraries/home-manager/default.nix +++ b/libraries/home-manager/default.nix @@ -21,7 +21,6 @@ in ./programs/jq ./programs/kube ./programs/lsd - ./programs/skhd ./programs/yabai # os systems diff --git a/libraries/home-manager/programs/skhd/default.nix b/libraries/home-manager/programs/skhd/default.nix deleted file mode 100644 index 7f895f89..00000000 --- a/libraries/home-manager/programs/skhd/default.nix +++ /dev/null @@ -1,52 +0,0 @@ -{ config, pkgs, lib, ... }: -with lib; - -let - inherit (pkgs.stdenvNoCC.hostPlatform) isDarwin; - cfg = config.services.skhd; - -in -{ - options.services.skhd = { - enable = mkEnableOption "skhd"; - - package = mkPackageOption pkgs "skhd" { }; - - config = mkOption { - type = types.lines; - default = ""; - example = "alt + shift - r : chunkc quit"; - description = "Config to use for skhdrc."; - }; - }; - - config = mkMerge [ - { - assertions = [ - { - assertion = cfg.enable -> isDarwin; - message = "Nix skhd only supports darwin."; - } - ]; - } - - (mkIf cfg.enable { - xdg.configFile = { - "skhd/skhdrc".text = cfg.config; - }; - - launchd.agents.skhd = { - enable = true; - config = { - ProgramArguments = - [ "${cfg.package}/bin/skhd" ] - ++ optionals (cfg.config != "") [ "-c" "${config.xdg.configHome}/skhd/skhdrc" ]; - KeepAlive = true; - ProcessType = "Interactive"; - StandardOutPath = "${config.xdg.cacheHome}/skhd.log"; - StandardErrorPath = "${config.xdg.cacheHome}/skhd.log"; - }; - }; - }) - ]; -} diff --git a/modules/darwin/home.nix b/modules/darwin/home.nix index f73e2d23..fa74da06 100644 --- a/modules/darwin/home.nix +++ b/modules/darwin/home.nix @@ -70,7 +70,6 @@ ../darwin/programs/desktop ../darwin/programs/hammerspoon ../darwin/programs/homerow - ../darwin/programs/skhd ../darwin/programs/yabai ]; diff --git a/modules/darwin/programs/hammerspoon/default.nix b/modules/darwin/programs/hammerspoon/default.nix index bb829b39..5c547f79 100644 --- a/modules/darwin/programs/hammerspoon/default.nix +++ b/modules/darwin/programs/hammerspoon/default.nix @@ -6,7 +6,11 @@ config = { HSUploadCrashData = 0; - MJConfigFile = "~/.config/hammerspoon/init.lua"; + MJConfigFile = "${config.xdg.configHome}/hammerspoon/init.lua"; }; }; + + xdg.configFile = { + "hammerspoon/init.lua".source = ./files/init.lua; + }; } diff --git a/modules/darwin/programs/hammerspoon/files/init.lua b/modules/darwin/programs/hammerspoon/files/init.lua new file mode 100644 index 00000000..f54d944f --- /dev/null +++ b/modules/darwin/programs/hammerspoon/files/init.lua @@ -0,0 +1,97 @@ +-- Vim bindings +local left = "h"; +local down = "j"; +local up = "k"; +local right = "l"; + +-- Utils +function strip(string) + return string:gsub("\n[^\n]*$", "") +end + +-- Prepare +local bin = { + yabai = strip(hs.execute("command -v yabai", true)), +} + +-- Hammerspoon +hs.hotkey.bind({"alt", "shift"}, "r", function() hs.reload() end) + +-- Terminal +hs.hotkey.bind({"alt"}, "Return", function() hs.execute("open -na WezTerm.app") end) + +-- Yabai +function yabai(args) + hs.task.new( + bin.yabai, + function(exitCode, stdOut, stdErr) + if stdErr ~= "" then + hs.alert.show(strip(stdErr)) + end + end, + function(task, stdOut, stdErr) + if stdErr ~= "" then + hs.alert.show(strip(stdErr)) + end + end, + args + ):start() +end + +-- Yabai (focus window) +hs.hotkey.bind({"alt"}, left, function() yabai({"-m", "window", "--focus", "west"}) end) +hs.hotkey.bind({"alt"}, down, function() yabai({"-m", "window", "--focus", "south"}) end) +hs.hotkey.bind({"alt"}, up, function() yabai({"-m", "window", "--focus", "north"}) end) +hs.hotkey.bind({"alt"}, right, function() yabai({"-m", "window", "--focus", "east"}) end) +hs.hotkey.bind({"alt", "shift"}, "Space", function() + yabai({"-m", "window", "--toggle", "float"}) + yabai({"-m", "window", "--grid", "4:4:1:1:2:2"}) +end) + +-- Yabai (move window) +hs.hotkey.bind({"alt", "shift"}, left, function() yabai({"-m", "window", "--swap", "west"}) end) +hs.hotkey.bind({"alt", "shift"}, down, function() yabai({"-m", "window", "--swap", "south"}) end) +hs.hotkey.bind({"alt", "shift"}, up, function() yabai({"-m", "window", "--swap", "north"}) end) +hs.hotkey.bind({"alt", "shift"}, right, function() yabai({"-m", "window", "--swap", "east"}) end) + +-- Yabai (switch workspace) +hs.hotkey.bind({"alt"}, "1", function() yabai({"-m", "space", "--focus", "1"}) end) +hs.hotkey.bind({"alt"}, "2", function() yabai({"-m", "space", "--focus", "2"}) end) +hs.hotkey.bind({"alt"}, "3", function() yabai({"-m", "space", "--focus", "3"}) end) +hs.hotkey.bind({"alt"}, "4", function() yabai({"-m", "space", "--focus", "4"}) end) +hs.hotkey.bind({"alt"}, "5", function() yabai({"-m", "space", "--focus", "5"}) end) +hs.hotkey.bind({"alt"}, "6", function() yabai({"-m", "space", "--focus", "6"}) end) +hs.hotkey.bind({"alt"}, "7", function() yabai({"-m", "space", "--focus", "7"}) end) +hs.hotkey.bind({"alt"}, "8", function() yabai({"-m", "space", "--focus", "8"}) end) +hs.hotkey.bind({"alt"}, "9", function() yabai({"-m", "space", "--focus", "9"}) end) +hs.hotkey.bind({"alt"}, "0", function() yabai({"-m", "space", "--focus", "10"}) end) + +-- Yabai (move to workspace) +hs.hotkey.bind({"alt", "shift"}, "1", function() yabai({"-m", "window", "--space", "1"}) end) +hs.hotkey.bind({"alt", "shift"}, "2", function() yabai({"-m", "window", "--space", "2"}) end) +hs.hotkey.bind({"alt", "shift"}, "3", function() yabai({"-m", "window", "--space", "3"}) end) +hs.hotkey.bind({"alt", "shift"}, "4", function() yabai({"-m", "window", "--space", "4"}) end) +hs.hotkey.bind({"alt", "shift"}, "5", function() yabai({"-m", "window", "--space", "5"}) end) +hs.hotkey.bind({"alt", "shift"}, "6", function() yabai({"-m", "window", "--space", "6"}) end) +hs.hotkey.bind({"alt", "shift"}, "7", function() yabai({"-m", "window", "--space", "7"}) end) +hs.hotkey.bind({"alt", "shift"}, "8", function() yabai({"-m", "window", "--space", "8"}) end) +hs.hotkey.bind({"alt", "shift"}, "9", function() yabai({"-m", "window", "--space", "9"}) end) +hs.hotkey.bind({"alt", "shift"}, "0", function() yabai({"-m", "window", "--space", "10"}) end) + +-- Yabai (split, layout) +hs.hotkey.bind({"alt"}, "b", function() yabai({"-m", "window", "--insert", "south"}) end) +hs.hotkey.bind({"alt"}, "v", function() yabai({"-m", "window", "--insert", "east"}) end) +hs.hotkey.bind({"alt"}, "e", function() yabai({"-m", "window", "--toggle", "split"}) end) + +-- Yabai (fullscreen) +hs.hotkey.bind({"alt"}, "f", function() yabai({"-m", "window", "--toggle", "zoom-fullscreen"}) end) + +-- Homerow +hs.pathwatcher.new( + os.getenv('HOME') .. '/Library/Preferences/com.superultra.Homerow.plist', + function(paths) + hs.execute('defaults write com.superultra.Homerow activation-count 0') + end +):start() + +hs.alert.show("Config loaded") diff --git a/modules/darwin/programs/skhd/default.nix b/modules/darwin/programs/skhd/default.nix deleted file mode 100644 index c037aa6d..00000000 --- a/modules/darwin/programs/skhd/default.nix +++ /dev/null @@ -1,77 +0,0 @@ -{ config, lib, pkgs, ... }: - -let - mod = "alt"; - left = "h"; - right = "l"; - up = "k"; - down = "j"; - - bins = { - skhd = "${pkgs.skhd}/bin/skhd"; - yabai = "${pkgs.yabai}/bin/yabai"; - }; - -in -{ - services.skhd = { - enable = true; - - config = builtins.concatStringsSep "\n" [ - # Core skhd - "${mod} + shift - r : ${bins.skhd} --reload" - - # Terminal - "${mod} - return : open -na WezTerm.app" - "ctrl + cmd - t : open -na WezTerm.app" - - # Kill window - "${mod} - w : ${bins.yabai} -m window --close" - - # Focus window - "${mod} - ${left} : ${bins.yabai} -m window --focus west" - "${mod} - ${down} : ${bins.yabai} -m window --focus south" - "${mod} - ${up} : ${bins.yabai} -m window --focus north" - "${mod} - ${right} : ${bins.yabai} -m window --focus east" - "${mod} + shift - space : ${bins.yabai} -m window --toggle float && yabai -m window --grid 4:4:1:1:2:2" - - # Move window - "${mod} + shift - ${left} : ${bins.yabai} -m window --swap west" - "${mod} + shift - ${down} : ${bins.yabai} -m window --swap south" - "${mod} + shift - ${up} : ${bins.yabai} -m window --swap north" - "${mod} + shift - ${right} : ${bins.yabai} -m window --swap east" - - # Switch workspace - "${mod} - 1 : ${bins.yabai} -m space --focus 1" - "${mod} - 2 : ${bins.yabai} -m space --focus 2" - "${mod} - 3 : ${bins.yabai} -m space --focus 3" - "${mod} - 4 : ${bins.yabai} -m space --focus 4" - "${mod} - 5 : ${bins.yabai} -m space --focus 5" - "${mod} - 6 : ${bins.yabai} -m space --focus 6" - "${mod} - 7 : ${bins.yabai} -m space --focus 7" - "${mod} - 8 : ${bins.yabai} -m space --focus 8" - "${mod} - 9 : ${bins.yabai} -m space --focus 9" - "${mod} - 0 : ${bins.yabai} -m space --focus 10" - - # Move to workspace - "${mod} + shift - 1 : ${bins.yabai} -m window --space 1" - "${mod} + shift - 2 : ${bins.yabai} -m window --space 2" - "${mod} + shift - 3 : ${bins.yabai} -m window --space 3" - "${mod} + shift - 4 : ${bins.yabai} -m window --space 4" - "${mod} + shift - 5 : ${bins.yabai} -m window --space 5" - "${mod} + shift - 6 : ${bins.yabai} -m window --space 6" - "${mod} + shift - 7 : ${bins.yabai} -m window --space 7" - "${mod} + shift - 8 : ${bins.yabai} -m window --space 8" - "${mod} + shift - 9 : ${bins.yabai} -m window --space 9" - "${mod} + shift - 0 : ${bins.yabai} -m window --space 10" - - # Split, Layout - "${mod} - b : ${bins.yabai} -m window --insert south" - "${mod} - v : ${bins.yabai} -m window --insert east" - "${mod} - e : ${bins.yabai} -m window --toggle split" - - # Fullscreen - "${mod} - f : ${bins.yabai} -m window --toggle zoom-fullscreen" - ]; - }; -} diff --git a/modules/shared/programs/wezterm/default.nix b/modules/shared/programs/wezterm/default.nix index 241c525f..f53ae663 100644 --- a/modules/shared/programs/wezterm/default.nix +++ b/modules/shared/programs/wezterm/default.nix @@ -28,7 +28,7 @@ in automatically_reload_config = true, color_scheme = 'default', font = wezterm.font('${font-family}'), - font_size = 13, + font_size = ${builtins.toString(font-size)}, front_end = 'WebGpu', hide_tab_bar_if_only_one_tab = true, window_decorations = 'RESIZE',