Skip to content

Commit

Permalink
feat: Use hammerspoon instead of skhd
Browse files Browse the repository at this point in the history
  • Loading branch information
sudosubin committed Dec 15, 2024
1 parent 5618d8a commit f602541
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 133 deletions.
1 change: 0 additions & 1 deletion libraries/home-manager/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ in
./programs/jq
./programs/kube
./programs/lsd
./programs/skhd
./programs/yabai

# os systems
Expand Down
52 changes: 0 additions & 52 deletions libraries/home-manager/programs/skhd/default.nix

This file was deleted.

1 change: 0 additions & 1 deletion modules/darwin/home.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
../darwin/programs/desktop
../darwin/programs/hammerspoon
../darwin/programs/homerow
../darwin/programs/skhd
../darwin/programs/yabai
];

Expand Down
6 changes: 5 additions & 1 deletion modules/darwin/programs/hammerspoon/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
97 changes: 97 additions & 0 deletions modules/darwin/programs/hammerspoon/files/init.lua
Original file line number Diff line number Diff line change
@@ -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")
77 changes: 0 additions & 77 deletions modules/darwin/programs/skhd/default.nix

This file was deleted.

2 changes: 1 addition & 1 deletion modules/shared/programs/wezterm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit f602541

Please sign in to comment.