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")
|
2016-01-02 12:40:34 -08:00
|
|
|
end
|
2016-01-06 21:56:41 -08:00
|
|
|
return false
|
2016-01-02 12:40:34 -08:00
|
|
|
end
|
|
|
|
|
2016-01-06 21:56:41 -08:00
|
|
|
local function tmuxPressKey(mod, key)
|
2016-01-02 12:40:34 -08:00
|
|
|
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)
|
2016-01-02 12:40:34 -08:00
|
|
|
-- 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
|
2016-01-02 12:40:34 -08:00
|
|
|
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"})
|
2016-01-02 12:40:34 -08:00
|
|
|
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)
|
|
|
|
|
2016-01-02 12:40:34 -08:00
|
|
|
-- 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()
|
2016-01-02 12:40:34 -08:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
.bind({'cmd', 'shift'}, 'w', util.call(hs.window, 'close')) -- close pane/window
|