helm/hammerspoon/apps/iterm.lua

63 lines
1.5 KiB
Lua
Raw Normal View History

2015-12-25 03:43:34 -08:00
local tmux_prefix = {{'ctrl'}, 'c'}
2016-01-06 21:56:41 -08:00
-- Helpers
2015-12-25 03:43:34 -08:00
local function isTmuxWindow()
2016-01-06 21:56:41 -08:00
local win = hs.window.focusedWindow()
if win then
return win:title():find("tmux")
end
2016-01-06 21:56:41 -08:00
return false
end
2016-01-06 21:56:41 -08:00
local function tmuxPressKey(mod, key)
if isTmuxWindow() then
hs.eventtap.keyStroke({'ctrl'}, 'c')
hs.eventtap.keyStroke(mod, key)
return true
end
return false
2015-12-25 03:43:34 -08:00
end
2016-01-06 21:56:20 -08:00
-- App settings
local iterm2
2015-12-25 03:43:34 -08:00
App.new("iTerm2")
2016-01-06 21:56:20 -08:00
.onLaunched(function (self, app)
-- cmd+N for switching tmux windows
for i = 1,9 do
i = tostring(i)
self.bind({'cmd'}, i, function()
if isTmuxWindow() then
os.execute("/usr/local/bin/tmux select-window -t " .. i)
end
end)
end
2016-01-06 21:56:41 -08:00
-- new tmux window
self.bind({'cmd'}, 'n', function()
2016-01-06 21:56:41 -08:00
if not tmuxPressKey({}, 'c') then
2016-02-17 17:33:55 -08:00
app:selectMenuItem({"Shell", "New Window"})
end
end)
2016-01-06 21:56:41 -08:00
-- new window
self.bind({'cmd', 'shift'}, 'n', function()
2016-02-17 17:33:55 -08:00
app:selectMenuItem({"Shell", "New Window"})
2016-01-06 21:56:41 -08:00
end)
-- close pane/window
self.bind({'cmd'}, 'w', function()
2016-01-06 21:56:41 -08:00
if not tmuxPressKey({}, 'x') then
2016-02-17 17:33:55 -08:00
app:selectMenuItem({"Shell", "Close"})
2016-01-06 21:56:41 -08:00
end
end)
-- detach tmux before quitting iterm
self.bind({'cmd'}, 'q', function()
if not tmuxPressKey({}, 'd') then
2016-02-17 17:33:55 -08:00
app:kill()
end
end)
end)
.bind({'cmd', 'shift'}, 'w', util.call(hs.window, 'close')) -- close pane/window