.hammerspoon/init.lua

Sat, 19 Jun 2021 21:43:19 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Sat, 19 Jun 2021 21:43:19 -0500
changeset 915
55a1c83b3417
parent 908
fa7c0607c00e
child 987
556f618e117a
permissions
-rw-r--r--

spin out stubexec

hs.window.animationDuration = 0

-- aliases and partial bindings to make life easier
local bindKey  = hs.hotkey.bind
local cmd      = hs.fnutils.partial(bindKey, {"cmd"})
local cmdShift = hs.fnutils.partial(bindKey, {"cmd", "shift"})
local cmdCtrl  = hs.fnutils.partial(bindKey, {"cmd", "ctrl"})

function focusedWindow()
  return hs.window.focusedWindow() or hs.window.desktop()
end

function focusTo(direction)
  local fn = hs.getObjectMetatable('hs.window')['focusWindow' .. direction]
  return function ()
    fn(focusedWindow(), nil, nil, true)
  end
end

function findOrLaunch(a)
  return hs.application.find(a) or hs.application.open(a, 3)
end

-- and the key bindings
cmdShift('r', hs.reload)

cmd('k',  focusTo('North'))
cmd('up', focusTo('North'))

cmd('j',    focusTo('South'))
cmd('down', focusTo('South'))

cmd('h',    focusTo('West'))
cmd('left', focusTo('West'))

cmd('l',     focusTo('East'))
cmd('right', focusTo('East'))

cmdShift('up', function () focusedWindow():maximize() end)

cmdShift('down', function () focusedWindow():minimize() end)

cmdShift('left',  function () focusedWindow():moveToUnit(hs.layout.left50) end)
cmdShift('right', function () focusedWindow():moveToUnit(hs.layout.right50) end)

cmdCtrl('left',  function () focusedWindow():moveOneScreenWest() end)
cmdCtrl('right', function () focusedWindow():moveOneScreenEast() end)

cmd('return', function ()
  local a = findOrLaunch('iTerm')
  a:selectMenuItem({"Shell", "New Window"})
  a:activate()
end)

cmdShift('return', function ()
  os.execute(os.getenv('SHELL')..' -l -i -c "exec mvim"')
end)

cmdCtrl('return', function ()
  local a = findOrLaunch('MacVim')
  a:selectMenuItem({"File", "New Window"})
  a:activate()
end)

mercurial