Add initial hammerspoon config
This commit is contained in:
parent
74d3807ffc
commit
417ec78a1d
19
hammerspoon/apps.lua
Normal file
19
hammerspoon/apps.lua
Normal file
|
@ -0,0 +1,19 @@
|
|||
|
||||
forApp("Finder", function (appName, eventType, appObject)
|
||||
-- Bring all Finder windows forward when one gets activated
|
||||
appObject:selectMenuItem({"Window", "Bring All to Front"})
|
||||
end)
|
||||
|
||||
forApp("iTerm2", function (appName, _, appObject)
|
||||
-- cmd+N switch-to-window shortcuts in Tmux
|
||||
for i = 1,9 do
|
||||
i = tostring(i)
|
||||
bind(appName, 'cmd', i, function ()
|
||||
if string.find(appObject:focusedWindow():title(), ".*tmux") then
|
||||
-- os.execute("/usr/local/bin/tmux select-window -t " .. i)
|
||||
hs.eventtap.keyStroke({'ctrl'}, 'c')
|
||||
hs.eventtap.keyStroke({}, i)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end)
|
56
hammerspoon/core.lua
Normal file
56
hammerspoon/core.lua
Normal file
|
@ -0,0 +1,56 @@
|
|||
-- TODO: Turn into App class
|
||||
|
||||
core = {}
|
||||
core.__index = core
|
||||
|
||||
function core.reload()
|
||||
hs.reload()
|
||||
hs.alert("Config reloaded!")
|
||||
end
|
||||
|
||||
-- App-specific code, runs when you launch or switch to another app
|
||||
apps = {}
|
||||
function forApp(name, func)
|
||||
if type(name) == 'table' then
|
||||
for i = 1, #name do
|
||||
apps[name[i]] = func
|
||||
end
|
||||
else
|
||||
apps[name] = func
|
||||
end
|
||||
end
|
||||
|
||||
-- App-specific keybinds
|
||||
lastApp = ""
|
||||
binds = {}
|
||||
function bind(app, mods, key, pressedfn, releasedfn, repeatfn)
|
||||
if not binds[app] then
|
||||
binds[app] = {}
|
||||
end
|
||||
if not binds[app][mods] then
|
||||
binds[app][mods] = {}
|
||||
end
|
||||
if binds[app][mods][key] then
|
||||
binds[app][mods][key]:enable()
|
||||
else
|
||||
binds[app][mods][key] = hs.hotkey.bind(mods, key, nil, pressedfn, releasedfn, repeatfn)
|
||||
end
|
||||
end
|
||||
|
||||
function appWatcher(appName, eventType, appObject)
|
||||
if (eventType == hs.application.watcher.activated) then
|
||||
if (lastApp ~= appName) and (binds[lastApp]) then
|
||||
for _, i in pairs(binds[lastApp]) do
|
||||
for _, j in pairs(i) do
|
||||
j:disable()
|
||||
end
|
||||
end
|
||||
end
|
||||
if apps[appName] then
|
||||
apps[appName](appName, eventType, appObject)
|
||||
lastApp = appName
|
||||
end
|
||||
end
|
||||
end
|
||||
local appWatcher = hs.application.watcher.new(appWatcher)
|
||||
appWatcher:start()
|
14
hammerspoon/init.lua
Normal file
14
hammerspoon/init.lua
Normal file
|
@ -0,0 +1,14 @@
|
|||
require('core')
|
||||
|
||||
--
|
||||
require('modules/windows')
|
||||
|
||||
-- Globals
|
||||
screen = hs.screen.primaryScreen()
|
||||
|
||||
-- Modules
|
||||
require('keybinds')
|
||||
require('apps')
|
||||
require('urls')
|
||||
require('locations')
|
||||
|
17
hammerspoon/keybinds.lua
Normal file
17
hammerspoon/keybinds.lua
Normal file
|
@ -0,0 +1,17 @@
|
|||
k = hs.hotkey.modal.new('cmd', 'escape')
|
||||
|
||||
|
||||
-- Screen overlay
|
||||
local f = screen:frame()
|
||||
local r = hs.drawing.rectangle(hs.geometry(0, 0, f.w, f.h + 30))
|
||||
r:setAlpha(0.5)
|
||||
r:setFillColor(hs.drawing.color.black)
|
||||
r:bringToFront()
|
||||
|
||||
function k:entered() hs.alert("Command mode!"); r:show() end
|
||||
function k:exited() r:hide(); hs.alert("Bye bye") end
|
||||
|
||||
|
||||
-- Bindings
|
||||
k:bind('', 'escape', function() k:exit() end)
|
||||
k:bind('', 'r', function() core.reload() end)
|
0
hammerspoon/locations.lua
Normal file
0
hammerspoon/locations.lua
Normal file
2
hammerspoon/modules/windows.lua
Normal file
2
hammerspoon/modules/windows.lua
Normal file
|
@ -0,0 +1,2 @@
|
|||
-- TODO: Window management library
|
||||
|
4
hammerspoon/urls.lua
Normal file
4
hammerspoon/urls.lua
Normal file
|
@ -0,0 +1,4 @@
|
|||
-- hammerspoon://reload
|
||||
hs.urlevent.bind("reload", core.reload)
|
||||
|
||||
-- TODO: hammerspoon://org?search=keywords
|
Loading…
Reference in a new issue