From cb15dabd04d75c268ebe74135c7faf7898f2f922 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 7 Jan 2016 00:56:41 -0500 Subject: [PATCH] hs: fix iterm/tmux keybinds --- hammerspoon/apps/iterm.lua | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/hammerspoon/apps/iterm.lua b/hammerspoon/apps/iterm.lua index 7f96457c..9bd7db90 100644 --- a/hammerspoon/apps/iterm.lua +++ b/hammerspoon/apps/iterm.lua @@ -1,13 +1,16 @@ local tmux_prefix = {{'ctrl'}, 'c'} +-- Helpers local function isTmuxWindow() - return function () - hs.window.focusedWindow():title():find("tmux") + local win = hs.window.focusedWindow() + if win then + return win:title():find("tmux") end + return false end -local function tmuxpresskey(mod, key) +local function tmuxPressKey(mod, key) if isTmuxWindow() then hs.eventtap.keyStroke({'ctrl'}, 'c') hs.eventtap.keyStroke(mod, key) @@ -30,17 +33,29 @@ App.new("iTerm2") end) end - -- new window + -- new tmux window self.bind({'cmd'}, 'n', function() - if not tmuxpresskey({}, 'c') then - app:selectMenuItem({"Shell", "New Window"}) + if not tmuxPressKey({}, 'c') then + App.find("iTerm2"):selectMenuItem({"Shell", "New Window"}) end end) + -- new window + self.bind({'cmd', 'shift'}, 'n', function() + App.find("iTerm2"):selectMenuItem({"Shell", "New Window"}) + end) + -- close pane/window self.bind({'cmd'}, 'w', function() - if not tmuxpresskey({}, 'x') then - app:selectMenuItem({"Shell", "Close"}) + if not tmuxPressKey({}, 'x') then + App.find("iTerm2"):selectMenuItem({"Shell", "Close"}) + end + end) + + -- detach tmux before quitting iterm + self.bind({'cmd'}, 'q', function() + if not tmuxPressKey({}, 'd') then + App.find("iTerm2"):kill() end end) end)