Make movement bindings DRYer and begin making them dynamic

This commit is contained in:
Kenneth Benzie 2024-10-04 13:02:26 +01:00
parent 24e06b38a3
commit 4e2e456b87

View File

@ -39,26 +39,35 @@ config.keys = {
end), end),
}), }),
}, },
{
key = 'h',
mods = 'CTRL|SHIFT',
action = wezterm.action.ActivatePaneDirection('Left'),
},
{
key = 'l',
mods = 'CTRL|SHIFT',
action = wezterm.action.ActivatePaneDirection('Right'),
},
{
key = 'k',
mods = 'CTRL|SHIFT',
action = wezterm.action.ActivatePaneDirection('Up'),
},
{
key = 'j',
mods = 'CTRL|SHIFT',
action = wezterm.action.ActivatePaneDirection('Down'),
},
} }
local move_mods = 'CTRL|SHIFT'
local function send_key(window, pane)
-- TODO: Detect if tmux is running
-- Detect if vim/nvim is running
-- Failing that, check if there is only a single pane
return false
end
for _, map in pairs({
{ key = 'h', direction = 'Left' },
{ key = 'l', direction = 'Right' },
{ key = 'k', direction = 'Up' },
{ key = 'j', direction = 'Down' },
}) do
table.insert(config.keys, {
key = map.key,
mods = move_mods,
action = wezterm.action_callback(function(window, pane)
if send_key(window, pane) then
window:perform_action(
wezterm.action.SendKey({ key = map.key, modes = move_mods }), pane)
else
window:perform_action(
wezterm.action.ActivatePaneDirection(map.direction), pane)
end
end),
})
end
return config return config