Skip to content

Instantly share code, notes, and snippets.

@mathisto
Created October 5, 2020 13:46
Show Gist options
  • Save mathisto/d1a4a57867345717ac17da3f306cf73d to your computer and use it in GitHub Desktop.
Save mathisto/d1a4a57867345717ac17da3f306cf73d to your computer and use it in GitHub Desktop.
My `~/.hammerspoon/init.lua` config file. Uses a QMK bound F19 key to allow for optional "modified" hyper chords.
hs.application.enableSpotlightForNameSearches(true)
hs.notify.new({title="Hammerspoon", informativeText="Config loaded"}):send()
hs.window.animationDuration = 0 -- Animations are silly
-- Load Spoons
hs.loadSpoon("WinWin")
hs.loadSpoon("ReloadConfiguration")
spoon.ReloadConfiguration:start()
-- Bind the Hyper key
hyper = hs.hotkey.modal.new({}, nil)
hyper.pressed = function() hyper:enter() end
hyper.released = function() hyper:exit() end
hs.hotkey.bind({}, 'F19', hyper.pressed, hyper.released)
-- Helpers Functions
launch = function(appname)
hs.application.launchOrFocus(appname)
hyper.triggered = true
end
-- Monitors
left_acer = hs.screen.find(478251797)
center_dell = hs.screen.find(722497435)
right_dell = hs.screen.find(722476764)
-- Application Aliases
browser = 'Google Chrome'
editor = 'Visual Studio Code'
terminal = 'iTerm'
database = 'DataGrip'
rest_client = 'Postman Canary'
music = 'Spotify'
slack = 'Slack'
chat = 'Discord'
-- Application Invocation
applicationHotkeys = {
a = 'Activity Monitor',
b = browser,
e = editor,
i = terminal,
d = database,
f = 'Finder',
m = 'Messages',
r = rest_client,
p = music,
s = slack,
c = chat,
w = 'Hammerspoon'
}
for key, app in pairs(applicationHotkeys) do
hyper:bind({}, key, nil, function() launch(app); hyper:exit(); end)
end
hyper:bind({}, 'space', nil, function() launch('Alfred 4'); hyper:exit(); end)
-- Window Managment
hyper:bind({}, "h", nil, function() spoon.WinWin:moveAndResize("halfleft") end)
hyper:bind({}, "j", nil, function() hs.window.focusedWindow():moveToScreen(hs.window.focusedWindow():screen():next()) end)
hyper:bind({}, "k", nil, function() hs.window.focusedWindow():maximize() end)
hyper:bind({}, "l", nil, function() spoon.WinWin:moveAndResize("halfright") end)
-- WARNING - Work in Progress
-- 3 Monitor Battlestation Layout
hyper:bind({}, ";", nil, function()
local windowLayout = {
{browser, nil, left_acer, hs.layout.maximized, nil, nil},
{'iTerm2', nil, center_dell, hs.layout.right50, nil, nil},
{'Code', nil, center_dell, hs.layout.left50, nil, nil},
{database, nil, right_dell, hs.layout.maximized, nil, nil},
{slack, nil, right_dell, hs.layout.left50, nil, nil},
{chat, nil, right_dell, hs.layout.right50, nil, nil},
{music, nil, right_dell, hs.layout.right50, nil, nil},
}
hs.layout.apply(windowLayout)
hs.application.launchOrFocus(browser)
hs.application.launchOrFocus(editor)
hs.application.launchOrFocus(terminal)
hs.application.launchOrFocus(slack)
hs.application.launchOrFocus(music)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment