Skip to content

Instantly share code, notes, and snippets.

@dorelljames
Created February 19, 2026 12:52
Show Gist options
  • Select an option

  • Save dorelljames/1328e15bc758541c8ed97922b57c7953 to your computer and use it in GitHub Desktop.

Select an option

Save dorelljames/1328e15bc758541c8ed97922b57c7953 to your computer and use it in GitHub Desktop.
Hammerspoon: Toggle Ghostty on current Space with Option+Escape
-- Toggle Ghostty on current Space with Option+Escape
-- Only activates if Ghostty has a window on the current Space.
-- If no Ghostty window here, does nothing (no desktop switching).
hs.hotkey.bind({"alt"}, "escape", function()
local app = hs.application.find("ghostty")
if not app then
hs.application.launchOrFocus("Ghostty")
return
end
if app:isFrontmost() then
app:hide()
return
end
-- Check if any Ghostty window is on the current space
local currentSpace = hs.spaces.focusedSpace()
local allWins = app:allWindows()
for _, win in ipairs(allWins) do
local winSpaces = hs.spaces.windowSpaces(win:id())
if winSpaces and hs.fnutils.contains(winSpaces, currentSpace) then
app:activate()
return
end
end
-- No Ghostty window on this space — do nothing
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment