Skip to content

Instantly share code, notes, and snippets.

@antonioalmeida
Last active December 15, 2016 16:34
Show Gist options
  • Save antonioalmeida/5f3421ebb0567a6b1fe986341c17ac99 to your computer and use it in GitHub Desktop.
Save antonioalmeida/5f3421ebb0567a6b1fe986341c17ac99 to your computer and use it in GitHub Desktop.
My Hammerspoon's config file
-- Hammerspoon configuration, heavily influenced by sdegutis default configuration
-- init grid
hs.grid.MARGINX = 0
hs.grid.MARGINY = 0
hs.grid.GRIDWIDTH = 8
hs.grid.GRIDHEIGHT = 4
-- disable animation
hs.window.animationDuration = 0
-- hotkey hyper
-- Note: CAPS LOCK key is mapped to ctrl via Karabiner-Elements
local hyper = {"ctrl"}
local hyper_cmd = {"ctrl", "cmd"}
local hyper_shift = {"ctrl", "shift"}
--------------------------------------------------------------------------------
-- application help
local function open_help()
help_str = "s - Spotify, a - Terminal, 2 - Pathfinder, " ..
"3 - Chrome, 4 - Dash, 5 - Trello, 6 - Quiver"
hs.alert.show(
help_str, 2)
end
-- Launch applications
hs.hotkey.bind(hyper_cmd, 's', function () hs.application.launchOrFocus("Spotify") end)
hs.hotkey.bind(hyper_cmd, 'a', function () hs.application.launchOrFocus("iTerm") end)
hs.hotkey.bind(hyper_cmd, '2', function () hs.application.launchOrFocus("Finder") end)
hs.hotkey.bind(hyper_cmd, 'c', function () hs.application.launchOrFocus("Safari") end)
-- hyper_cmd '4' reserved for dash global key
hs.hotkey.bind(hyper_cmd, '5', function () hs.application.launchOrFocus("Trello X") end)
hs.hotkey.bind(hyper_cmd, '6', function () hs.application.launchOrFocus("Quiver") end)
hs.hotkey.bind(hyper_cmd, '\\', open_help)
-- global operations
hs.hotkey.bind(hyper, 'w', function() hs.grid.snap(hs.window.focusedWindow()) end)
hs.hotkey.bind(hyper, 's', function() hs.fnutil.map(hs.window.visibleWindows(), hs.grid.snap) end)
-- adjust grid size
--hs.hotkey.bind(hyper, '=', function() hs.grid.adjustWidth( 1) end)
--hs.hotkey.bind(hyper, '-', function() hs.grid.adjustWidth(-1) end)
--hs.hotkey.bind(hyper, ']', function() hs.grid.adjustHeight( 1) end)
--hs.hotkey.bind(hyper, '[', function() hs.grid.adjustHeight(-1) end)
-- change focus
hs.hotkey.bind(hyper_shift, 'H', function() hs.window.focusedWindow():focusWindowWest() end)
hs.hotkey.bind(hyper_shift, 'L', function() hs.window.focusedWindow():focusWindowEast() end)
hs.hotkey.bind(hyper_shift, 'K', function() hs.window.focusedWindow():focusWindowNorth() end)
hs.hotkey.bind(hyper_shift, 'J', function() hs.window.focusedWindow():focusWindowSouth() end)
-- maximize window
hs.hotkey.bind(hyper, 'f', hs.grid.maximizeWindow)
-- multi monitor
hs.hotkey.bind(hyper, 'N', hs.grid.pushWindowNextScreen)
hs.hotkey.bind(hyper, 'P', hs.grid.pushWindowPrevScreen)
-- move windows
hs.hotkey.bind(hyper, 'H', hs.grid.pushWindowLeft)
hs.hotkey.bind(hyper, 'J', hs.grid.pushWindowDown)
hs.hotkey.bind(hyper, 'K', hs.grid.pushWindowUp)
hs.hotkey.bind(hyper, 'L', hs.grid.pushWindowRight)
-- resize windows
hs.hotkey.bind(hyper, 'Y', hs.grid.resizeWindowThinner)
hs.hotkey.bind(hyper, 'U', hs.grid.resizeWindowShorter)
hs.hotkey.bind(hyper, 'I', hs.grid.resizeWindowTaller)
hs.hotkey.bind(hyper, 'O', hs.grid.resizeWindowWider)
-- Window Hints !! Very Useful !!
hs.hotkey.bind(hyper, '.', hs.hints.windowHints)
--Spotify--
hs.hotkey.bind(hyper_cmd, "P", function()
if hs.spotify.isRunning() then
hs.notify.new({title="Spotify", autoWithdraw=true, contentImage=hs.image.imageFromPath("/Applications/Spotify.app/Contents/Resources/Icon.icns"), subTitle=hs.spotify.getCurrentArtist(), informativeText=hs.spotify.getCurrentTrack()}):send()
end
end)
-- Caffeine
local caffeine = hs.menubar.new()
function setCaffeineDisplay(state)
if state then
caffeine:setTitle("AWAKE")
else
caffeine:setTitle("SLEEPY")
end
end
function caffeineClicked()
setCaffeineDisplay(hs.caffeinate.toggle("displayIdle"))
end
if caffeine then
caffeine:setClickCallback(caffeineClicked)
setCaffeineDisplay(hs.caffeinate.get("displayIdle"))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment