From 1fe2dfddae5cee43774479b41fec92d21fd65196 Mon Sep 17 00:00:00 2001 From: Haak Saxberg Date: Mon, 14 Sep 2015 22:43:05 -0700 Subject: [PATCH] baby hammerspoon config --- mac-files/.hammerspoon/init.lua | 172 ++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 mac-files/.hammerspoon/init.lua diff --git a/mac-files/.hammerspoon/init.lua b/mac-files/.hammerspoon/init.lua new file mode 100644 index 0000000..5948323 --- /dev/null +++ b/mac-files/.hammerspoon/init.lua @@ -0,0 +1,172 @@ +-------------------------------------------- +-- Set up +----------------------------------------------- + +local hyper = {"shift", "cmd", "alt", "ctrl"} + +hs.window.animationDuration = 0 + +----------------------------------------------- +-- hyper d for left one half window +----------------------------------------------- + +hs.hotkey.bind(hyper, 'd', function() + if hs.window.focusedWindow() then + local win = hs.window.focusedWindow() + 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) + else + hs.alert.show("No active window") + end +end) + +----------------------------------------------- +-- hyper g for right one half window +----------------------------------------------- + +hs.hotkey.bind(hyper, 'g', function() + if hs.window.focusedWindow() then + local win = hs.window.focusedWindow() + 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) + else + hs.alert.show("No active window") + end +end) + +----------------------------------------------- +-- hyper f for fullscreen +----------------------------------------------- + +hs.hotkey.bind(hyper, 'f', function() + if hs.window.focusedWindow() then + local win = hs.window.focusedWindow() + 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) + else + hs.alert.show("No active window") + end +end) + +----------------------------------------------- +-- hyper r for top left one quarter window +----------------------------------------------- + +hs.hotkey.bind(hyper, 'r', function() + if hs.window.focusedWindow() then + local win = hs.window.focusedWindow() + 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 / 2 + win:setFrame(f) + else + hs.alert.show("No active window") + end +end) + +----------------------------------------------- +-- hyper t for top right one quarter window +----------------------------------------------- + +hs.hotkey.bind(hyper, 't', function() + if hs.window.focusedWindow() then + local win = hs.window.focusedWindow() + 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 / 2 + win:setFrame(f) + else + hs.alert.show("No active window") + end +end) + +----------------------------------------------- +-- hyper v for bottom left one quarter window +----------------------------------------------- + +hs.hotkey.bind(hyper, 'v', function() + if hs.window.focusedWindow() then + local win = hs.window.focusedWindow() + local f = win:frame() + local screen = win:screen() + local max = screen:frame() + + f.x = max.x + (max.w / 2) + f.y = max.y + (max.h / 2) + f.w = max.w / 2 + f.h = max.h / 2 + win:setFrame(f) + else + hs.alert.show("No active window") + end +end) + +----------------------------------------------- +-- hyper c for bottom right one quarter window +----------------------------------------------- + +hs.hotkey.bind(hyper, 'c', function() + if hs.window.focusedWindow() then + local win = hs.window.focusedWindow() + 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 / 2 + f.h = max.h / 2 + win:setFrame(f) + else + hs.alert.show("No active window") + end +end) + +----------------------------------------------- +-- Reload config on write +----------------------------------------------- + +function reload_config(files) + hs.reload() +end +hs.pathwatcher.new(os.getenv("HOME") .. "/.hammerspoon/", reload_config):start() +hs.alert.show("Config loaded") + +----------------------------------------------- +-- Hyper i to show window hints +----------------------------------------------- + +hs.hotkey.bind(hyper, 'i', function() + hs.hints.windowHints() +end)