109 lines
3.0 KiB
Lua
109 lines
3.0 KiB
Lua
local darkmode = require("Spoons/darkmode")
|
|
|
|
-- Variables
|
|
local hyperKey = {"alt", "shift", "ctrl", "cmd"}
|
|
-- termApplication = "Alacritty"
|
|
local termApplication = "WezTerm"
|
|
|
|
-- Highlight the currently focused window
|
|
hs.window.highlight.start()
|
|
|
|
-- Enable spotlight to search applications by name
|
|
hs.application.enableSpotlightForNameSearches(true)
|
|
|
|
-- Reload configuration automatically
|
|
local function reloadConfig(files)
|
|
local doReload = false
|
|
for _, file in pairs(files) do
|
|
if file:sub(-4) == ".lua" then
|
|
doReload = true
|
|
end
|
|
end
|
|
if doReload then
|
|
hs.reload()
|
|
end
|
|
end
|
|
|
|
local myWatcher = hs.pathwatcher.new(os.getenv("HOME") .. "/.hammerspoon/", reloadConfig):start()
|
|
hs.alert.show("hs.config updated")
|
|
|
|
-- Allow a scratchpad-like behavior for a certain app with a key combination
|
|
local function scratchpadAppWithCombination(modifier, key, appName)
|
|
hs.hotkey.bind(modifier, key, function()
|
|
local app = hs.application.get(appName)
|
|
if app then
|
|
space = hs.spaces.activeSpaceOnScreen(hs.screen.mainScreen())
|
|
if not app:mainWindow() then
|
|
app:selectMenuItem({appName, "New OS window"})
|
|
elseif app:isFrontmost() then
|
|
app:hide()
|
|
else
|
|
app:unhide()
|
|
hs.spaces.moveWindowToSpace(app:focusedWindow(), space)
|
|
app:activate()
|
|
end
|
|
else
|
|
hs.application.launchOrFocus(appName)
|
|
end
|
|
end)
|
|
end
|
|
|
|
-- Focus a window with a combination
|
|
LastFocusedWindow = nil
|
|
local function focusAppWithCombination(modifier, key, appName)
|
|
hs.hotkey.bind(modifier, key, function()
|
|
local app = hs.application.get(appName)
|
|
if app then
|
|
if app:focusedWindow() == hs.window.focusedWindow() then
|
|
LastFocusedWindow:focus()
|
|
LastFocusedWindow = app:mainWindow()
|
|
else
|
|
LastFocusedWindow = hs.window.focusedWindow()
|
|
-- hs.application.launchOrFocus(appName)
|
|
app:mainWindow():focus()
|
|
end
|
|
else
|
|
hs.alert.show("iTerm not running")
|
|
end
|
|
end)
|
|
end
|
|
|
|
-- Setup
|
|
scratchpadAppWithCombination({"cmd", "shift"}, "-", "Obsidian")
|
|
-- scratchpadAppWithCombination(hyperKey, "-", "Notion")
|
|
scratchpadAppWithCombination({"ctrl"}, "return", termApplication)
|
|
|
|
-- Dark mode toggles
|
|
local function toggleMattermostTheme(dark)
|
|
print('theme changed to dark:', dark)
|
|
end
|
|
darkmode.addHandler(toggleMattermostTheme)
|
|
|
|
-- Test
|
|
|
|
-- function safariMouseBack()
|
|
|
|
-- end
|
|
|
|
-- termBinds = {}
|
|
|
|
-- function enableBinds()
|
|
-- -- hs.console.printStyledtext("term focused")
|
|
-- for k, v in pairs(termBinds) do
|
|
-- v:enable()
|
|
-- end
|
|
-- end
|
|
|
|
-- function disableBinds()
|
|
-- -- hs.console.printStyledtext("term unfocused")
|
|
-- for k, v in pairs(termBinds) do
|
|
-- v:disable()
|
|
-- end
|
|
-- end
|
|
|
|
-- local wf = hs.window.filter
|
|
|
|
-- wf_safari = wf.new {'Safari'}
|
|
-- wf_safari:subscribe(wf.windowFocused, enableBinds)
|
|
-- wf_safari:subscribe(wf.windowUnfocused, disableBinds)
|