Last active
December 8, 2020 19:38
-
-
Save sprig/7cfb5664fc52fda8f2a88529ce94f49f to your computer and use it in GitHub Desktop.
Hammerspoon config
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
brew tap homebrew/versions | |
brew install lua53 | |
## Don't remember now whether local works, possibly need to install via sudo | |
luarocks-5.3 install --local set | |
# sudo luarocks-5.3 install set |
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
---- Definitions | |
-- Set objects | |
local Set = require("Set") | |
-- Reload config | |
function reload() | |
hs.alert('Reloading Config') | |
hs.reload() | |
end | |
-- Launch App | |
launch = function(appname) | |
hs.alert(appname) | |
hs.application.launchOrFocus(appname) | |
k.triggered = true | |
end | |
-- Show window picker | |
expose = hs.expose.new() | |
-- set up your windowfilter | |
-- default windowfilter: only visible windows, all Spaces | |
-- expose2 = hs.expose.new(hs.window.filter.new():trackSpaces(true):setDefaultFilter()) -- include minimized/hidden windows, current Space only | |
-- expose_browsers = hs.expose.new{'Safari','Google Chrome'} -- specialized expose for your dozens of browser windows :) | |
function toggle_expose () | |
expose:toggleShow() | |
end | |
-- Window Movement -- | |
function LeftHalf () | |
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) | |
end | |
function RightHalf () | |
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) | |
end | |
function UpperHalf () | |
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 /2 | |
win:setFrame(f) | |
end | |
function LowerHalf () | |
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 | |
f.h = max.h /2 | |
win:setFrame(f) | |
end | |
function Maximize () | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:fullFrame() | |
win:setFrame(max) | |
end | |
function Rotate () | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
if (f.w > max.w - 10) then -- Window is maximized | |
LeftHalf() | |
elseif (f.x > max.x - 10) and (f.x < max.x + 10)then -- Window is on the left | |
RightHalf() | |
else | |
win:maximize() | |
end | |
end | |
function move_win_to_next_screen () | |
local win = hs.window.focusedWindow() | |
local screen = win:screen() | |
local nxt = screen:next() | |
win:moveToScreen(nxt) | |
end | |
-- Paste! | |
function paste_keystrokes () | |
hs.eventtap.keyStrokes(hs.pasteboard.getContents()) | |
end | |
function list_windows () | |
local apps = hs.application.runningApplications() | |
local app_set = Set:new(apps) | |
for n,app in pairs(app_set:tolist()) do | |
for m,win in pairs(app:allWindows(app)) do | |
local app_title = app:title() | |
local win_title = win:title() | |
if win_title ~= "" then | |
hs.alert(app_title .. " | " .. win_title, 1) | |
end | |
end | |
end | |
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
------ Bootstrap ------ | |
-- Package manager init | |
require("luarocks.loader") | |
-- Load our functions | |
require("functions") | |
-- Diable Animations | |
hs.window.animationDuration = 0 | |
----- Config ----- | |
-- Meaning of Hyper | |
full_hyper = {"cmd", "alt", "ctrl"} | |
slim_hyper = {"cmd", "alt"} | |
-- Just in case, have a simple reloader. | |
hs.hotkey.bind(slim_hyper, "R", reload) | |
---- Config for the actual 'Hyper', i.e. F18, i.e. caps lock. | |
-- App Shortcuts | |
app_keys = { | |
E = "Emacs"; | |
F = "Finder"; | |
C = "Google Chrome"; | |
M = "Mathematica"; | |
A = "Evernote"; | |
T = "Todoist"; | |
K = "Skim"; | |
} | |
-- Function running shortcuts | |
func_keys = { | |
{'Left', LeftHalf}, | |
{'Right', RightHalf}, | |
{'Up', UpperHalf}, | |
{'Down', LowerHalf}, | |
{'X', Maximize}, | |
{'R', reload}, | |
{'L', hs.caffeinate.lockScreen}, | |
{'V', paste_keystrokes}, | |
{'Return', move_win_to_next_screen}, | |
{';', list_windows}, | |
{'Z', toggle_expose} | |
} | |
-- Shortcuts sending fake hyper | |
full_hyper_keys = {'s', 'p', '`', 'f1', 'f2'} | |
slim_hyper_keys = {'d'} | |
full_hyper_keys_exit = {{'Tab', {{},'Return'}}} | |
require("modal") | |
hs.alert('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
---- Definitions | |
-- Set objects | |
local Set = require("Set") | |
-- Reload config | |
function reload() | |
hs.alert('Reloading Config') | |
hs.reload() | |
end | |
-- Launch App | |
launch = function(appname) | |
hs.alert(appname) | |
hs.application.launchOrFocus(appname) | |
k.triggered = true | |
end | |
-- Show window picker | |
expose = hs.expose.new() | |
-- set up your windowfilter | |
-- default windowfilter: only visible windows, all Spaces | |
-- expose2 = hs.expose.new(hs.window.filter.new():trackSpaces(true):setDefaultFilter()) -- include minimized/hidden windows, current Space only | |
-- expose_browsers = hs.expose.new{'Safari','Google Chrome'} -- specialized expose for your dozens of browser windows :) | |
function toggle_expose () | |
expose:toggleShow() | |
end | |
-- Window Movement -- | |
function LeftHalf () | |
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) | |
end | |
function RightHalf () | |
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) | |
end | |
function UpperHalf () | |
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 /2 | |
win:setFrame(f) | |
end | |
function LowerHalf () | |
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 | |
f.h = max.h /2 | |
win:setFrame(f) | |
end | |
function Maximize () | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:fullFrame() | |
win:setFrame(max) | |
end | |
function Rotate () | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
if (f.w > max.w - 10) then -- Window is maximized | |
LeftHalf() | |
elseif (f.x > max.x - 10) and (f.x < max.x + 10)then -- Window is on the left | |
RightHalf() | |
else | |
win:maximize() | |
end | |
end | |
function move_win_to_next_screen () | |
local win = hs.window.focusedWindow() | |
local screen = win:screen() | |
local nxt = screen:next() | |
win:moveToScreen(nxt) | |
end | |
-- Paste! | |
function paste_keystrokes () | |
hs.eventtap.keyStrokes(hs.pasteboard.getContents()) | |
end | |
function list_windows () | |
local apps = hs.application.runningApplications() | |
local app_set = Set:new(apps) | |
for n,app in pairs(app_set:tolist()) do | |
for m,win in pairs(app:allWindows(app)) do | |
local app_title = app:title() | |
local win_title = win:title() | |
if win_title ~= "" then | |
hs.alert(app_title .. " | " .. win_title, 1) | |
end | |
end | |
end | |
end |
Thanks @vjpr - I added the setup part to this gist now :-)
Note in particular that symlinking as in the comment is not necessary, turns out.
The homebrew/versions
tap was deprecated at some point. To do the same now:
brew install [email protected]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See Hammerspoon/hammerspoon#363 (comment) for how to get
luarocks.loader
as used in this gist working.