-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
swap hammerspoon configs from yabai to aerospace
Signed-off-by: clux <[email protected]>
- Loading branch information
Showing
3 changed files
with
116 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,28 @@ | ||
mash = {"⌘", "⌥", "⌃"} | ||
|
||
local function toggleApp(name) | ||
function aerospace(args) | ||
hs.task.new("/opt/homebrew/bin/aerospace", function(ud, ...) | ||
hs.inspect(table.pack(...)) | ||
return true | ||
end, args):start() | ||
end | ||
|
||
|
||
local function activateApp(name) | ||
local app = hs.application.find(name) | ||
if not app or app:isHidden() then | ||
hs.application.launchOrFocus(name) | ||
elseif hs.application.frontmostApplication() ~= app then | ||
app:activate() | ||
else | ||
-- NB: does not bring back fullscreen if we were fullscreen.. | ||
-- Could maybe write a dedicated toggler that remembers fullscreen, but don't care that much. | ||
app:hide() | ||
-- unfortunately we cannot swap out easily with aerospace | ||
-- hiding the window would mean an empty workspace or pulling in another window | ||
-- thus we hardcode the toggle to go back to 3 for now | ||
aerospace({"workspace", "3"}) | ||
end | ||
end | ||
|
||
-- Global terminal toggle | ||
hs.hotkey.bind({}, "F1", function() toggleApp("alacritty") end) | ||
|
||
-- Reload yabai | ||
hs.hotkey.bind(mash, "r", function() hs.reload(); os.execute("/opt/homebrew/bin/yabai --restart-service"); end) | ||
hs.alert("HS + yabai loaded") | ||
|
||
--function bindCmd(key, cmd) | ||
-- hs.hotkey.bind({"shift", "alt"}, key, function() os.execute(cmd) end) | ||
--end | ||
|
||
-- Yabai | ||
local function yabai(commands) | ||
for _, cmd in ipairs(commands) do | ||
os.execute("/opt/homebrew/bin/yabai -m " .. cmd) | ||
end | ||
end | ||
-- bind on alt/shift only | ||
-- | ||
-- For adopters: my binds ends up being shift-alt on a windows keyboard | ||
-- ..but that is AFTER remapping Control and Command on the keyboard globally in mac settings | ||
-- change these two binds to something that works | ||
-- (modifier switch + ctrl intercepted elsewhere in e.g. alacritty) | ||
local function alt(key, commands) | ||
hs.hotkey.bind({ "alt" }, key, function() | ||
yabai(commands) | ||
end) | ||
end | ||
local function shiftAlt(key, commands) | ||
hs.hotkey.bind({ "shift", "alt" }, key, function() | ||
yabai(commands) | ||
end) | ||
end | ||
|
||
|
||
hs.hotkey.bind({ "shift", "alt" }, "m", function() | ||
hs.execute("~/.config/yabai/focus.sh", true) | ||
end) | ||
|
||
-- window moving between monitors/spaces | ||
for i = 1, 9 do | ||
local num = tostring(i) | ||
alt(num, { "space --focus " .. num }) | ||
shiftAlt(num, { "window --space " .. num, "space --focus " .. num }) | ||
end | ||
--shiftAlt("tab", { "space --focus recent" }) | ||
|
||
-- NOTE: hjkl -> neio in colemak - use as arrow keys | ||
local homeRow = { n = "west", e = "south", i = "north", o = "east" } | ||
|
||
for key, direction in pairs(homeRow) do | ||
alt(key, { "window --focus " .. direction }) | ||
shiftAlt(key, { "window --swap " .. direction }) | ||
end | ||
|
||
-- window resize | ||
shiftAlt("down", { "window --resize bottom:0:20" }) -- increase down | ||
shiftAlt("right", { "window --resize right:20:0" }) -- increase right | ||
shiftAlt("up", { "window --resize bottom:0:-20" }) -- decrease down | ||
shiftAlt("left", { "window --resize right:-20:0" }) -- decrease right | ||
|
||
-- mode toggles for spaces and windows | ||
--shiftAlt("y", { "space --layout bsp" }) | ||
--shiftAlt("u", { "space --layout stack" }) | ||
--shiftAlt(";", { "space --layout float" }) --probably only want to do this for windows only? | ||
alt("f", { "window --toggle zoom-fullscreen" }) | ||
shiftAlt("f", { "window --toggle native-fullscreen" }) | ||
alt("l", { "window --toggle float", "window --grid 8:10:1:1:8:6" }) -- unfloat/float + center | ||
shiftAlt("l", { "window --toggle topmost", "window --grid 5:5:4:1:4:4" }) -- pin cornered on a ws | ||
|
||
-- NB: alt-f only works on mac if you keep modifiers in the same position | ||
|
||
-- mini pip window, note; does not retain properties correctly on yabai restart | ||
--shiftAlt("p", { "window --toggle pip", "window --toggle float", "window --toggle sticky", "window --toggle topmost" }) | ||
--shiftAlt("v", { "space --toggle padding", "space --toggle gap" }) | ||
|
||
-- layout experiments | ||
shiftAlt("r", { "space --rotate 90" }) | ||
-- Global terminal activation | ||
hs.hotkey.bind({}, "F1", function() activateApp("alacritty") end) | ||
hs.hotkey.bind(mash, "r", function() hs.reload(); aerospace("reload-config"); end) | ||
hs.alert("HS + aerospace loaded") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
mash = {"⌘", "⌥", "⌃"} | ||
|
||
-- yabai variant. of init.lua | ||
-- worked great, but not using it atm due to SIP not being unlockable now. | ||
|
||
local function toggleApp(name) | ||
local app = hs.application.find(name) | ||
if not app or app:isHidden() then | ||
hs.application.launchOrFocus(name) | ||
elseif hs.application.frontmostApplication() ~= app then | ||
app:activate() | ||
else | ||
-- NB: does not bring back fullscreen if we were fullscreen.. | ||
-- Could maybe write a dedicated toggler that remembers fullscreen, but don't care that much. | ||
app:hide() | ||
end | ||
end | ||
|
||
-- Global terminal toggle | ||
hs.hotkey.bind({}, "F1", function() toggleApp("alacritty") end) | ||
|
||
-- Reload yabai | ||
hs.hotkey.bind(mash, "r", function() hs.reload(); os.execute("/opt/homebrew/bin/yabai --restart-service"); end) | ||
hs.alert("HS + yabai loaded") | ||
|
||
--function bindCmd(key, cmd) | ||
-- hs.hotkey.bind({"shift", "alt"}, key, function() os.execute(cmd) end) | ||
--end | ||
|
||
-- Yabai | ||
local function yabai(commands) | ||
for _, cmd in ipairs(commands) do | ||
os.execute("/opt/homebrew/bin/yabai -m " .. cmd) | ||
end | ||
end | ||
-- bind on alt/shift only | ||
-- | ||
-- For adopters: my binds ends up being shift-alt on a windows keyboard | ||
-- ..but that is AFTER remapping Control and Command on the keyboard globally in mac settings | ||
-- change these two binds to something that works | ||
-- (modifier switch + ctrl intercepted elsewhere in e.g. alacritty) | ||
local function alt(key, commands) | ||
hs.hotkey.bind({ "alt" }, key, function() | ||
yabai(commands) | ||
end) | ||
end | ||
local function shiftAlt(key, commands) | ||
hs.hotkey.bind({ "shift", "alt" }, key, function() | ||
yabai(commands) | ||
end) | ||
end | ||
|
||
|
||
hs.hotkey.bind({ "shift", "alt" }, "m", function() | ||
hs.execute("~/.config/yabai/focus.sh", true) | ||
end) | ||
|
||
-- window moving between monitors/spaces | ||
for i = 1, 9 do | ||
local num = tostring(i) | ||
alt(num, { "space --focus " .. num }) | ||
shiftAlt(num, { "window --space " .. num, "space --focus " .. num }) | ||
end | ||
--shiftAlt("tab", { "space --focus recent" }) | ||
|
||
-- NOTE: hjkl -> neio in colemak - use as arrow keys | ||
local homeRow = { n = "west", e = "south", i = "north", o = "east" } | ||
|
||
for key, direction in pairs(homeRow) do | ||
alt(key, { "window --focus " .. direction }) | ||
shiftAlt(key, { "window --swap " .. direction }) | ||
end | ||
|
||
-- window resize | ||
shiftAlt("down", { "window --resize bottom:0:20" }) -- increase down | ||
shiftAlt("right", { "window --resize right:20:0" }) -- increase right | ||
shiftAlt("up", { "window --resize bottom:0:-20" }) -- decrease down | ||
shiftAlt("left", { "window --resize right:-20:0" }) -- decrease right | ||
|
||
-- mode toggles for spaces and windows | ||
--shiftAlt("y", { "space --layout bsp" }) | ||
--shiftAlt("u", { "space --layout stack" }) | ||
--shiftAlt(";", { "space --layout float" }) --probably only want to do this for windows only? | ||
alt("f", { "window --toggle zoom-fullscreen" }) | ||
shiftAlt("f", { "window --toggle native-fullscreen" }) | ||
alt("l", { "window --toggle float", "window --grid 8:10:1:1:8:6" }) -- unfloat/float + center | ||
shiftAlt("l", { "window --toggle topmost", "window --grid 5:5:4:1:4:4" }) -- pin cornered on a ws | ||
|
||
-- NB: alt-f only works on mac if you keep modifiers in the same position | ||
|
||
-- mini pip window, note; does not retain properties correctly on yabai restart | ||
--shiftAlt("p", { "window --toggle pip", "window --toggle float", "window --toggle sticky", "window --toggle topmost" }) | ||
--shiftAlt("v", { "space --toggle padding", "space --toggle gap" }) | ||
|
||
-- layout experiments | ||
shiftAlt("r", { "space --rotate 90" }) |