Skip to content

Instantly share code, notes, and snippets.

@kevinhughes27
Created January 22, 2015 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinhughes27/ca3b2535e374f9ca2c09 to your computer and use it in GitHub Desktop.
Save kevinhughes27/ca3b2535e374f9ca2c09 to your computer and use it in GitHub Desktop.
my half done config for hydra (osx window manager, now https://github.com/sdegutis/mjolnir) using thirds
-- autostart hydra
autolaunch.set(true)
-- watch for changes
pathwatcher.new(os.getenv("HOME") .. "/.hydra/", hydra.reload):start()
-- notify on start
hydra.alert("Hydra config loaded", 0.5)
-- open a repl
-- the repl is a Lua prompt; type "print('hello world')"
-- when you're in the repl, type "help" to get started
-- almost all readline functionality works in the repl
hotkey.bind({"cmd", "ctrl", "alt"}, "R", repl.open)
-- save the time when updates are checked
function checkforupdates()
updates.check()
settings.set('lastcheckedupdates', os.time())
end
-- show a helpful menu
menu.show(function()
local updatetitles = {[true] = "Install Update", [false] = "Check for Update..."}
local updatefns = {[true] = updates.install, [false] = checkforupdates}
local hasupdate = (updates.newversion ~= nil)
return {
{title = "Reload Config", fn = hydra.reload},
{title = "Open REPL", fn = repl.open},
{title = "-"},
{title = "About", fn = hydra.showabout},
{title = updatetitles[hasupdate], fn = updatefns[hasupdate]},
{title = "Quit Hydra", fn = os.exit},
}
end)
function movewindow(direction)
return function()
local win = window.focusedwindow()
local newframe = win:screen():frame_without_dock_or_menu()
-- hydra.alert(tostring(win.size(win).w), 0.5)
-- wndow is 1/2 make 2/3
if win.size(win).w == newframe.w / 2 then
newframe.w = newframe.w * 2/3
-- window is 2/3 make 1/3
elseif win.size(win).w == newframe.w * 2/3 then
newframe.w = newframe.w / 3
-- window is 1/3 reset to 1/2
elseif win.size(win).w == newframe.w / 3 then
newframe.w = newframe.w / 2
-- window is new set to 1/2
else
newframe.w = newframe.w / 2
end
-- stick to the right edge
if direction == "right" then
newframe.x = win:screen():frame_without_dock_or_menu().w - newframe.w
end
win:setframe(newframe)
end
end
hotkey.bind({"cmd", "alt"}, "right", movewindow("right"))
hotkey.bind({"cmd", "alt"}, "left", movewindow("left"))
-- fullscreen window with ext.win.margin
function fullscreen()
local win = window.focusedwindow()
local screen = win:screen():frame_without_dock_or_menu()
win:setframe(screen)
end
hotkey.bind({"cmd", "alt"}, "up", fullscreen)
-- show available updates
local function showupdate()
os.execute('open https://github.com/sdegutis/Hydra/releases')
end
-- what to do when an update is checked
function updates.available(available)
if available then
notify.show("Hydra update available", "", "Click here to see the changelog and maybe even install it", "showupdate")
else
hydra.alert("No update available.")
end
end
-- check for updates every week
timer.new(timer.weeks(1), checkforupdates):start()
notify.register("showupdate", showupdate)
-- if this is your first time running Hydra, you're launching it more than a week later, check now
local lastcheckedupdates = settings.get('lastcheckedupdates')
if lastcheckedupdates == nil or lastcheckedupdates <= os.time() - timer.days(7) then
checkforupdates()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment