Skip to content

Instantly share code, notes, and snippets.

@amine2233
Last active February 18, 2017 23:15
Show Gist options
  • Save amine2233/53edca8c50530e1d9b350860f378c7ec to your computer and use it in GitHub Desktop.
Save amine2233/53edca8c50530e1d9b350860f378c7ec to your computer and use it in GitHub Desktop.
My Hammerspoon
-- Hotkey mash
local mash = {"cmd", "alt", "ctrl"}
local mash_move = {"cmd", "ctrl"}
local mash_app = {"shift","ctrl","alt"}
hs.alert("Reloaded Config")
-- instant window resizing
hs.window.animationDuration = 0
-- position save for division theerd screen
local positionTheerd = 0
-- Resize window to tile horizontally
hs.hotkey.bind(mash, "h", function()
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 / 2
f.h = max.h
win:setFrame(f)
end)
-- Resize window to tile horizontally
hs.hotkey.bind(mash, "l", function()
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 + max.w / 2
f.y = max.y
f.w = max.w / 2
f.h = max.h
win:setFrame(f)
end)
-- Resize window to tile vertically
hs.hotkey.bind(mash, "k", function()
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)
-- Resize window to tile vertically
hs.hotkey.bind(mash, "j", function()
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)
-- Fullscreen
hs.hotkey.bind(mash, "F", function()
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
win:setFrame(f)
end)
-- Multi monitor
-- Move Next / Preivous Screen
hs.hotkey.bind(mash_move, "N", hs.grid.pushWindowNextScreen)
hs.hotkey.bind(mash_move, "P", hs.grid.pushWindowPrevScreen)
-- Caffeine, allow machine to sleep or not
--local caffeine = hs.menubar.new()
--function setCaffeineDisplay(state)
-- if state then
-- caffeine:setTitle("!zZz")
-- else
-- caffeine:setTitle("zZz")
-- end
--end
--function caffeineClicked()
-- setCaffeineDisplay(hs.caffeinate.toggle("displayIdle"))
--end
--if caffeine then
-- caffeine:setClickCallback(caffeineClicked)
-- setCaffeineDisplay(hs.caffeinate.get("displayIdle"))
--end
-- application help
local function open_help()
help_str = "I - iTerm, P - Pathfinder, F - Firefox, " ..
"G - Chrome, D - Dash, X - Trello, Q - Quiver" ..
"N - PhpStorm, S - Safari, M - Markdown, L - SnippetsLab" ..
hs.alert.show(
help_str, 2)
end
-- Launch applications
hs.hotkey.bind(mash_app, 'I', function () hs.application.launchOrFocus("iTerm") end)
hs.hotkey.bind(mash_app, 'P', function () hs.application.launchOrFocus("Path Finder") end)
hs.hotkey.bind(mash_app, 'G', function () hs.application.launchOrFocus("Google Chrome") end)
hs.hotkey.bind(mash_app, 'F', function () hs.application.launchOrFocus("Firefox") end)
hs.hotkey.bind(mash_app, 'S', function () hs.application.launchOrFocus("Safari") end)
-- mash_app '4' reserved for dash global key
hs.hotkey.bind(mash_app, 'X', function () hs.application.launchOrFocus("Trello X") end)
hs.hotkey.bind(mash_app, 'Q', function () hs.application.launchOrFocus("Quiver") end)
hs.hotkey.bind(mash_app, 'D', function () hs.application.launchOrFocus("Dash") end)
hs.hotkey.bind(mash_app, 'M', function () hs.application.launchOrFocus("Markdown Pro") end)
hs.hotkey.bind(mash_app, 'N', function () hs.application.launchOrFocus("PhpStorm") end)
hs.hotkey.bind(mash_app, 'L', function () hs.application.launchOrFocus("SnippetsLab") end)
hs.hotkey.bind(mash_app, 'H', open_help)
-- Reload config
hs.hotkey.bind(mash, "R", function()
hs.reload()
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment