More reliable tmux bindings + new indentation
This commit is contained in:
parent
72f18d6b34
commit
ea19734468
|
@ -2,21 +2,44 @@
|
||||||
local tmux_prefix = {{'ctrl'}, 'c'}
|
local tmux_prefix = {{'ctrl'}, 'c'}
|
||||||
|
|
||||||
local function isTmuxWindow()
|
local function isTmuxWindow()
|
||||||
return function ()
|
return function ()
|
||||||
hs.window.focusedWindow():title():find("tmux")
|
hs.window.focusedWindow():title():find("tmux")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function tmuxpresskey(mod, key)
|
||||||
|
if isTmuxWindow() then
|
||||||
|
hs.eventtap.keyStroke({'ctrl'}, 'c')
|
||||||
|
hs.eventtap.keyStroke(mod, key)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
App.new("iTerm2")
|
App.new("iTerm2")
|
||||||
.onInit(function (self)
|
.onInit(function (self, app)
|
||||||
-- cmd+N for switching tmux windows
|
-- cmd+N for switching tmux windows
|
||||||
for i = 1,9 do
|
for i = 1,9 do
|
||||||
i = tostring(i)
|
i = tostring(i)
|
||||||
self.bind({'cmd'}, i, function()
|
self.bind({'cmd'}, i, function()
|
||||||
os.execute("/usr/local/bin/tmux select-window -t " .. i)
|
if isTmuxWindow() then
|
||||||
end, isTmuxWindow)
|
os.execute("/usr/local/bin/tmux select-window -t " .. i)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
.bind({'cmd'}, 'n', invoke({tmux_prefix, 'c'}), isTmuxWindow) -- new window
|
end
|
||||||
.bind({'cmd'}, 'w', invoke({tmux_prefix, 'x'}), isTmuxWindow) -- close pane/window
|
|
||||||
.bind({'cmd', 'shift'}, 'w', util.call(hs.window, 'close')) -- close pane/window
|
-- new window
|
||||||
|
self.bind({'cmd'}, 'n', function()
|
||||||
|
if not tmuxpresskey({}, 'c') then
|
||||||
|
app:selectMenuItem({"Shell", "New Window"})
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- close pane/window
|
||||||
|
self.bind({'cmd'}, 'w', function()
|
||||||
|
if not tmuxpresskey({}, 'x') then
|
||||||
|
app:selectMenuItem({"Shell", "Close"})
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
.bind({'cmd', 'shift'}, 'w', util.call(hs.window, 'close')) -- close pane/window
|
||||||
|
|
Loading…
Reference in a new issue