Skip to content

Instantly share code, notes, and snippets.

@ChristianBagley
Forked from eltercero/init.lua
Created January 30, 2016 05:44
Show Gist options
  • Save ChristianBagley/cd0a2cd46e87b2c8da5b to your computer and use it in GitHub Desktop.
Save ChristianBagley/cd0a2cd46e87b2c8da5b to your computer and use it in GitHub Desktop.
Config file for hammerspoon
local hotkey = require "hs.hotkey"
local application = require "hs.application"
-- HOTKEYS
local mash = {"cmd", "alt", "ctrl"}
local app_opener = {"cmd", "ctrl"}
-- Helpers
function resize_and_move(direction)
return function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
if direction == "left" then f.x = max.x end
if direction == "right" then f.x = max.x + (max.w / 2) end
f.y = max.y
f.w = max.w / 2
f.h = max.h
win:setFrame(f)
end
end
local frameCache = {}
function toggle_window_maximized()
local win = hs.window.focusedWindow()
if frameCache[win:id()] then
win:setFrame(frameCache[win:id()])
frameCache[win:id()] = nil
else
frameCache[win:id()] = win:frame()
win:maximize()
end
end
function toggle_app(app_name)
return function()
local app = hs.appfinder.appFromName(app_name)
if not app then
application.launchOrFocus(app_name)
end
current_app = application.frontmostApplication()
if current_app == app then
app:hide()
else
application.launchOrFocus(app_name)
end
end
end
-- SHORTCUTS
-- Resize to half and move to the left
hotkey.bind(mash, "Left", resize_and_move('left'))
-- Resize to half and move to the right
hotkey.bind(mash, "Right", resize_and_move('right'))
-- Zoom the window (not fullscreen)
hotkey.bind(mash, "Up", toggle_window_maximized)
-- Focus or open apps
hotkey.bind( app_opener, "C", toggle_app("Google Chrome") )
hotkey.bind( app_opener, "S", toggle_app("Sublime Text") )
hotkey.bind( app_opener, "I", toggle_app("iTerm") )
hotkey.bind( app_opener, "L", toggle_app("Slack") )
hotkey.bind( app_opener, "K", toggle_app("Skype") )
hotkey.bind( app_opener, "T", toggle_app("Tweetbot") )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment