hs: fix iterm/tmux keybinds
This commit is contained in:
parent
d8c5bcc323
commit
cb15dabd04
|
@ -1,13 +1,16 @@
|
||||||
|
|
||||||
local tmux_prefix = {{'ctrl'}, 'c'}
|
local tmux_prefix = {{'ctrl'}, 'c'}
|
||||||
|
|
||||||
|
-- Helpers
|
||||||
local function isTmuxWindow()
|
local function isTmuxWindow()
|
||||||
return function ()
|
local win = hs.window.focusedWindow()
|
||||||
hs.window.focusedWindow():title():find("tmux")
|
if win then
|
||||||
|
return win:title():find("tmux")
|
||||||
end
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tmuxpresskey(mod, key)
|
local function tmuxPressKey(mod, key)
|
||||||
if isTmuxWindow() then
|
if isTmuxWindow() then
|
||||||
hs.eventtap.keyStroke({'ctrl'}, 'c')
|
hs.eventtap.keyStroke({'ctrl'}, 'c')
|
||||||
hs.eventtap.keyStroke(mod, key)
|
hs.eventtap.keyStroke(mod, key)
|
||||||
|
@ -30,17 +33,29 @@ App.new("iTerm2")
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- new window
|
-- new tmux window
|
||||||
self.bind({'cmd'}, 'n', function()
|
self.bind({'cmd'}, 'n', function()
|
||||||
if not tmuxpresskey({}, 'c') then
|
if not tmuxPressKey({}, 'c') then
|
||||||
app:selectMenuItem({"Shell", "New Window"})
|
App.find("iTerm2"):selectMenuItem({"Shell", "New Window"})
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- new window
|
||||||
|
self.bind({'cmd', 'shift'}, 'n', function()
|
||||||
|
App.find("iTerm2"):selectMenuItem({"Shell", "New Window"})
|
||||||
|
end)
|
||||||
|
|
||||||
-- close pane/window
|
-- close pane/window
|
||||||
self.bind({'cmd'}, 'w', function()
|
self.bind({'cmd'}, 'w', function()
|
||||||
if not tmuxpresskey({}, 'x') then
|
if not tmuxPressKey({}, 'x') then
|
||||||
app:selectMenuItem({"Shell", "Close"})
|
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)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in a new issue