Last active
August 29, 2015 14:24
-
-
Save kgust/d9df886995f6f15caf50 to your computer and use it in GitHub Desktop.
My Hammerspoon configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Replace Caffeine.app with 18 lines of Lua :D | |
| local caffeine = hs.menubar.new() | |
| function setCaffeineDisplay(state) | |
| local result | |
| if state then | |
| result = caffeine:setIcon("caffeine-on.pdf") | |
| else | |
| result = caffeine:setIcon("caffeine-off.pdf") | |
| end | |
| end | |
| function caffeineClicked() | |
| setCaffeineDisplay(hs.caffeinate.toggle("displayIdle")) | |
| end | |
| if caffeine then | |
| caffeine:setClickCallback(caffeineClicked) | |
| setCaffeineDisplay(hs.caffeinate.get("displayIdle")) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- | |
| -- HELPERS | |
| -- | |
| -- size window to left half | |
| function toLeft() | |
| local win = hs.window.focusedWindow() | |
| if win == nil then | |
| return | |
| end | |
| local frame = win:frame() | |
| local screen = win:screen() | |
| local max = screen:frame() | |
| frame.x = max.x | |
| frame.y = max.y | |
| frame.w = max.w / 2 | |
| frame.h = max.h | |
| win:setFrame(frame) | |
| end | |
| -- size window to bottom half | |
| function toBottom() | |
| local win = hs.window.focusedWindow() | |
| if win == nil then | |
| return | |
| end | |
| local f = win:frame() | |
| local screen = win:screen() | |
| local max = screen:frame() | |
| f.x = max.x | |
| f.y = max.y + (max.h / 2) | |
| f.w = max.w | |
| f.h = max.h / 2 | |
| win:setFrame(f) | |
| end | |
| -- size window to top half | |
| function toTop() | |
| local win = hs.window.focusedWindow() | |
| if win == nil then | |
| return | |
| end | |
| local f = win:frame() | |
| local screen = win:screen() | |
| local max = screen:frame() | |
| f.x = max.x | |
| f.y = max.y | |
| f.w = max.w | |
| f.h = max.h / 2 | |
| win:setFrame(f) | |
| end | |
| -- size window to right half | |
| function toRight() | |
| local win = hs.window.focusedWindow() | |
| if win == nil then | |
| return | |
| end | |
| local frame = win:frame() | |
| local screen = win:screen() | |
| local max = screen:frame() | |
| frame.x = max.x + (max.w / 2) | |
| frame.y = max.y | |
| frame.w = max.w / 2 | |
| frame.h = max.h | |
| win:setFrame(frame) | |
| end | |
| -- move window to the left | |
| function moveLeft() | |
| local win = hs.window.focusedWindow() | |
| if win == nil then | |
| return | |
| end | |
| local frame = win:frame() | |
| local screen = win:screen() | |
| local max = screen:frame() | |
| frame.x = frame.x - 20 | |
| win:setFrame(frame) | |
| end | |
| -- move window down | |
| function moveDown() | |
| local win = hs.window.focusedWindow() | |
| if win == nil then | |
| return | |
| end | |
| local frame = win:frame() | |
| local screen = win:screen() | |
| local max = screen:frame() | |
| frame.y = frame.y + 20 | |
| win:setFrame(frame) | |
| end | |
| -- move window up | |
| function moveUp() | |
| local win = hs.window.focusedWindow() | |
| if win == nil then | |
| return | |
| end | |
| local frame = win:frame() | |
| local screen = win:screen() | |
| local max = screen:frame() | |
| frame.y = frame.y - 20 | |
| win:setFrame(frame) | |
| end | |
| -- move window to the right | |
| function moveRight() | |
| local win = hs.window.focusedWindow() | |
| if win == nil then | |
| return | |
| end | |
| local frame = win:frame() | |
| local screen = win:screen() | |
| local max = screen:frame() | |
| frame.x = frame.x + 20 | |
| win:setFrame(frame) | |
| end | |
| -- move window to the east | |
| function moveEast() | |
| local win = hs.window.focusedWindow() | |
| if win == false then | |
| return | |
| end | |
| win:moveOneScreenEast(0) | |
| end | |
| -- move window to the west | |
| function moveWest() | |
| local win = hs.window.focusedWindow() | |
| if win == false then | |
| return | |
| end | |
| win:moveOneScreenWest(0) | |
| end | |
| -- Defines for window maximize toggler | |
| local frameCache = {} | |
| -- Toggle a window between its normal size, and being maximized | |
| function toggleWindowMaximized() | |
| 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 | |
| -- Toggle an application between being the frontmost app, and being hidden | |
| function toggleApplication(_app) | |
| local app = hs.appfinder.appFromName(_app) | |
| if not app then | |
| -- FIXME: This should really launch _app | |
| return | |
| end | |
| local mainwin = app:mainWindow() | |
| if mainwin then | |
| if mainwin == hs.window.focusedWindow() then | |
| mainwin:application():hide() | |
| else | |
| mainwin:application():activate(true) | |
| mainwin:application():unhide() | |
| mainwin:focus() | |
| end | |
| end | |
| end | |
| function reloadConfig(files) | |
| 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 | |
| hs.pathwatcher.new(os.getenv("HOME") .. "/.hammerspoon/", reloadConfig):start() | |
| hs.alert.show("Config loaded") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- https://github.com/cmsj/hammerspoon-config/blob/master/init.lua | |
| -- https://github.com/BrianGilbert/.hammerspoon/blob/master/init.lua | |
| require('functions') | |
| require('caffeine') | |
| -- init grid | |
| hs.grid.MARGINX = 0 | |
| hs.grid.MARGINY = 0 | |
| hs.grid.GRIDWIDTH = 2 | |
| hs.grid.GRIDHEIGHT = 2 | |
| -- Define some keyboard modifier variables | |
| -- mash = {"cmd", "shift"} | |
| local mash = {"⌘", "⇧"} | |
| -- mash_app = {"cmd", "alt", "ctrl"} | |
| local mash_app = {"⌘", "⌥", "⌃"} | |
| -- hyper = {"cmd", "alt", "ctrl", "shift"} | |
| local hyper = {"⌘", "⌥", "⌃", "⇧"} | |
| -- window animations (set to 0 to disable) | |
| -- hs.window.animationDuration = 0 | |
| local lcd = "Color LCD" | |
| local bigscreen = "HP Z30i" | |
| hs.hotkey.bind(hyper, "H", toLeft) | |
| hs.hotkey.bind(hyper, "Left", moveWest) | |
| hs.hotkey.bind(hyper, "J", toBottom) | |
| -- hs.hotkey.bind(hyper, "Down", toBottom) | |
| hs.hotkey.bind(hyper, "K", toTop) | |
| -- hs.hotkey.bind(hyper, "Up", toTop) | |
| hs.hotkey.bind(hyper, "L", toRight) | |
| hs.hotkey.bind(hyper, "Right", moveEast) | |
| hs.hotkey.bind(hyper, "U", moveLeft) | |
| hs.hotkey.bind(hyper, "I", moveDown) | |
| hs.hotkey.bind(hyper, "O", moveUp) | |
| hs.hotkey.bind(hyper, "P", moveRight) | |
| hs.hotkey.bind(hyper, 'RETURN', toggleWindowMaximized) | |
| hs.hotkey.bind(hyper, 'F', toggleWindowMaximized) | |
| -- Application hotkeys | |
| hs.hotkey.bind(hyper, 'E', function() toggleApplication("iTerm") end) | |
| hs.hotkey.bind(hyper, 'Q', function() toggleApplication("Safari") end) | |
| hs.hotkey.bind(hyper, 'Z', function() toggleApplication("Reeder") end) | |
| hs.hotkey.bind(hyper, 'W', function() toggleApplication("IRC") end) | |
| -- toggle window hints | |
| hs.hotkey.bind(mash, '.', hs.hints.windowHints) | |
| -- toggle apps | |
| hs.hotkey.bind(mash_app, 'C', function() hs.application.launchOrFocus('Google Chrome') end) | |
| hs.hotkey.bind(mash_app, 'I', function() hs.application.launchOrFocus('iTerm') end) | |
| hs.hotkey.bind(mash_app, 'S', function() hs.application.launchOrFocus('Sublime Text') end) | |
| hs.hotkey.bind(mash_app, 'M', function() hs.application.launchOrFocus('Sequel Pro') end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment