Last active
February 11, 2025 08:09
-
-
Save pythoninthegrass/f141261a0dd28a4549780e1eb0e9c0f3 to your computer and use it in GitHub Desktop.
wezterm + hammerspoon (quake mode)
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
-- SOURCE: https://github.com/wez/wezterm/issues/1751#issuecomment-2014752114 | |
-- brew install --cask hammerspoon | |
-- ~/.hammerspoon/init.lua | |
-- Import necessary Hammerspoon modules | |
local hotkey = require "hs.hotkey" | |
local application = require "hs.application" | |
local mouse = require "hs.mouse" | |
local screen = require "hs.screen" | |
local geometry = require "hs.geometry" | |
local spaces = require "hs.spaces" | |
local timer = require "hs.timer" | |
-- Detect the screen under the cursor | |
local function screenUnderCursor() | |
local mousePoint = mouse.getAbsolutePosition() | |
local screens = screen.allScreens() | |
for _, scr in ipairs(screens) do | |
if geometry.point(mousePoint):inside(scr:frame()) then | |
return scr | |
end | |
end | |
return nil | |
end | |
-- Bind a hotkey for launching an app on the screen where the cursor is located | |
local function bindHotkey(appName, key) | |
hotkey.bind({ "cmd" }, key, function() | |
local app = application.find(appName) | |
local currentScreen = screenUnderCursor() | |
if app then | |
if app:isFrontmost() then | |
app:hide() | |
else | |
local app_window = app:mainWindow() | |
if app_window and currentScreen then | |
local max = currentScreen:fullFrame() | |
local f = app_window:frame() | |
f.x = max.x | |
f.y = max.y | |
f.w = max.w | |
f.h = max.h | |
spaces.moveWindowToSpace(app_window, spaces.focusedSpace()) | |
timer.doAfter(0.2, function() | |
app_window:setFrame(f) | |
end) | |
app_window:focus() | |
end | |
end | |
else | |
application.launchOrFocus(appName) | |
timer.doAfter(0.5, function() | |
local launched_app = application.find(appName) | |
if launched_app then | |
local app_window = launched_app:mainWindow() | |
if app_window and currentScreen then | |
local max = currentScreen:fullFrame() | |
local f = app_window:frame() | |
f.x = max.x | |
f.y = max.y | |
f.w = max.w | |
f.h = max.h | |
app_window:setFrame(f) | |
app_window:focus() | |
end | |
end | |
end) | |
end | |
end) | |
end | |
-- Bind the hotkey for WezTerm | |
bindHotkey("WezTerm", "`") |
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
local wezterm = require 'wezterm' | |
local config = wezterm.config_builder() | |
local mux = wezterm.mux | |
local act = wezterm.action | |
wezterm.on('gui-startup', function() | |
local tab, pane, window = mux.spawn_window({}) | |
window:gui_window():maximize() | |
end) | |
local keys = { | |
{ key = 'd', mods = 'CMD', action = act.SplitPane { command = { domain = 'CurrentPaneDomain' }, direction = 'Right', size = { Percent = (50) }, top_level = false } }, | |
{ key = 'd', mods = 'CMD|SHIFT', action = act.SplitPane { command = { domain = 'CurrentPaneDomain' }, direction = 'Down', size = { Percent = (50) }, top_level = false } }, | |
{ key = '[', mods = 'CMD', action = act.ActivatePaneDirection 'Prev', }, | |
{ key = ']', mods = 'CMD', action = act.ActivatePaneDirection 'Next', }, | |
{ key = 'x', mods = 'CMD', action = act.CloseCurrentPane { confirm = false } }, | |
{ key = 'l', mods = 'CMD|SHIFT', action = act.ActivateTabRelative(1) }, | |
{ key = 'h', mods = 'CMD|SHIFT', action = act.ActivateTabRelative(-1) }, | |
{ key = 't', mods = 'CMD', action = act.SpawnTab 'CurrentPaneDomain' }, | |
{ key = 'w', mods = 'CMD', action = act.CloseCurrentTab { confirm = false } }, | |
{ key = 'R', mods = 'SHIFT|CTRL', action = act.ReloadConfiguration }, | |
{ key = '+', mods = 'CTRL', action = act.IncreaseFontSize }, | |
{ key = '-', mods = 'CTRL', action = act.DecreaseFontSize }, | |
{ key = '0', mods = 'CTRL', action = act.ResetFontSize }, | |
{ key = 'N', mods = 'SHIFT|CTRL', action = act.SpawnWindow }, | |
{ key = 'U', mods = 'SHIFT|CTRL', action = act.CharSelect { copy_on_select = true, copy_to = 'ClipboardAndPrimarySelection' } }, | |
{ key = 'b', mods = 'LEADER|CTRL', action = act.SendString '\\x02', }, | |
{ key = 'Enter', mods = 'LEADER', action = act.ActivateCopyMode, }, | |
{ key = 'Enter', mods = 'CMD', action = act.ActivateCopyMode }, | |
{ key = 'C', mods = 'SHIFT|CTRL', action = act.CopyTo 'Clipboard' }, | |
{ key = 'v', mods = 'CMD', action = act.PasteFrom 'Clipboard' }, | |
{ key = 'LeftArrow', mods = 'OPT', action = act.SendString '\x1bb' }, | |
{ key = 'RightArrow', mods = 'OPT', action = act.SendString '\x1bf' }, | |
{ | |
key = 'k', | |
mods = 'CTRL|ALT', | |
action = act.Multiple | |
{ | |
act.ClearScrollback 'ScrollbackAndViewport', | |
act.SendKey { key = 'L', mods = 'CTRL' } | |
} | |
}, | |
{ key = 'r', mods = 'LEADER', action = act.ActivateKeyTable { name = 'resize_pane', one_shot = false, }, }, | |
} | |
for i = 1, 9 do | |
table.insert(keys, { | |
key = tostring(i), | |
mods = 'CMD', | |
action = act.ActivateTab(i - 1) | |
}) | |
end | |
return { | |
automatically_reload_config = true, | |
warn_about_missing_glyphs = false, | |
default_prog = { 'bash', '-l' }, | |
default_cwd = wezterm.home_dir, | |
default_cursor_style = "BlinkingBlock", | |
cursor_blink_rate = 500, | |
animation_fps = 1, | |
cursor_blink_ease_in = "Constant", | |
cursor_blink_ease_out = "Constant", | |
window_decorations = "RESIZE", | |
inactive_pane_hsb = { | |
saturation = 0.8, | |
brightness = 0.7 | |
}, | |
color_scheme = 'AdventureTime', | |
font = wezterm.font('Hack Nerd Font Mono'), | |
font_size = 13, | |
line_height = 1.2, | |
use_dead_keys = false, | |
scrollback_lines = 5000, | |
adjust_window_size_when_changing_font_size = false, | |
hide_tab_bar_if_only_one_tab = true, | |
switch_to_last_active_tab_when_closing_tab = true, | |
window_frame = { | |
font = wezterm.font { family = 'Noto Sans', weight = 'Regular' }, | |
}, | |
disable_default_key_bindings = true, | |
keys = keys, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment