Skip to content

Instantly share code, notes, and snippets.

@cmsj cmsj/init.lua forked from HendrikRoth/init.lua
Last active Aug 29, 2015

Embed
What would you like to do?
local application = require "hs.application"
local tiling = require "hs.tiling" -- git clone https://github.com/dsanson/hs.tiling $HOME/.hammerspoon/hs/tiling
local hotkey = require "hs.hotkey"
local mash = {"ctrl", "cmd"}
local safari = nil
-- settings
hs.window.animationDuration = 0 -- disable window animations
-- tiling
hotkey.bind(mash, "c", function() tiling.cyclelayout() end)
hotkey.bind(mash, "j", function() tiling.cycle(1) end)
hotkey.bind(mash, "k", function() tiling.cycle(-1) end)
hotkey.bind(mash, "space", function() tiling.promote() end)
tiling.set('layouts', {
'fullscreen', 'main-vertical'
})
-- launching
hotkey.bind(mash, '1', function() application.launchOrFocus('iTerm') end)
hotkey.bind(mash, '2', function() application.launchOrFocus('Safari') end)
hotkey.bind(mash, '3', function() application.launchOrFocus('Finder') end)
hotkey.bind(mash, '4', function() application.launchOrFocus('Mail') end)
hotkey.bind(mash, '5', function() application.launchOrFocus('iTerm') end)
-- Safari tab keys
function safari_tab(num)
hs.applescript._applescript('tell front window of app "Safari" to set current tab to tab ' .. num)
end
safarimodal = hs.hotkey.modal.new()
for i = 1, 9, 1 do
safarimodal:bind({"cmd"}, tostring(i), function() safari_tab(i) end)
end
function applicationWatcher(app, event, appObject)
if app == 'Safari' then
if event == hs.application.watcher.activated then
safarimodal:enter()
elseif event == hs.application.watcher.deactivated then
safarimodal:exit()
end
end
end
hs.application.watcher.new(applicationWatcher):start()
-- automatic config reloading
function reload_config(files)
hs.reload()
end
hs.pathwatcher.new(os.getenv("HOME") .. "/.hammerspoon/", reload_config):start()
hs.alert.show("Config reloaded")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.