chore: formatting

This commit is contained in:
Dinesh Salunke 2024-10-19 08:07:35 +05:30
parent 6e2ccb46df
commit 038eff7610

View File

@ -1,102 +1,113 @@
local wezterm = require("wezterm") local wezterm = require("wezterm")
local act = wezterm.action local act = wezterm.action
local gui = wezterm.gui
local M = {} local M = {}
local direction_keys = { local direction_keys = {
Left = "h", Left = "h",
Down = "j", Down = "j",
Up = "k", Up = "k",
Right = "l", Right = "l",
-- reverse lookup -- reverse lookup
h = "Left", h = "Left",
j = "Down", j = "Down",
k = "Up", k = "Up",
l = "Right", l = "Right",
} }
-- if you are *NOT* lazy-loading smart-splits.nvim (recommended) -- if you are *NOT* lazy-loading smart-splits.nvim (recommended)
local function is_vim(pane) local function is_vim(pane)
-- this is set by the plugin, and unset on ExitPre in Neovim -- this is set by the plugin, and unset on ExitPre in Neovim
return pane:get_user_vars().IS_NVIM == "true" return pane:get_user_vars().IS_NVIM == "true"
end end
local function split_nav(resize_or_move, key) local function split_nav(resize_or_move, key)
return { return {
key = key, key = key,
mods = resize_or_move == "resize" and "META" or "CTRL", mods = resize_or_move == "resize" and "META" or "CTRL",
action = wezterm.action_callback(function(win, pane) action = wezterm.action_callback(function(win, pane)
if is_vim(pane) then if is_vim(pane) then
-- pass the keys through to vim/nvim -- pass the keys through to vim/nvim
win:perform_action({ win:perform_action({
SendKey = { key = key, mods = resize_or_move == "resize" and "META" or "CTRL" }, SendKey = { key = key, mods = resize_or_move == "resize" and "META" or "CTRL" },
}, pane) }, pane)
else else
if resize_or_move == "resize" then if resize_or_move == "resize" then
win:perform_action({ AdjustPaneSize = { direction_keys[key], 3 } }, pane) win:perform_action({ AdjustPaneSize = { direction_keys[key], 3 } }, pane)
else else
win:perform_action({ ActivatePaneDirection = direction_keys[key] }, pane) win:perform_action({ ActivatePaneDirection = direction_keys[key] }, pane)
end end
end end
end), end),
} }
end end
function M.options(config) function M.options(config)
-- --
config.leader = { key = "a", mods = "CTRL" } config.leader = { key = "a", mods = "CTRL" }
config.keys = { config.keys = {
{ key = "a", mods = "LEADER|CTRL", action = wezterm.action({ SendString = "\x01" }) }, {
{ key = "-", mods = "LEADER", action = wezterm.action({ SplitPane = { direction = "Down", size = { Percent = 25 } } }) }, key = "s",
{ mods = "LEADER",
key = "\\", action = wezterm.action_callback(function(win, pane)
mods = "LEADER", wezterm.log_info("Hello from callback!")
action = wezterm.action({ SplitPane = { direction = "Right", size = { Percent = 25 } } }) wezterm.log_info("WindowID:", win:window_id(), "PaneID:", pane:pane_id())
}, end),
{ key = "z", mods = "LEADER", action = "TogglePaneZoomState" }, },
{ key = "c", mods = "LEADER", action = wezterm.action({ SpawnTab = "CurrentPaneDomain" }) }, { key = "a", mods = "LEADER|CTRL", action = wezterm.action({ SendString = "\x01" }) },
{ key = "x", mods = "LEADER", action = wezterm.action.CloseCurrentPane({ confirm = true }) }, {
{ key = "n", mods = "LEADER", action = wezterm.action.ToggleFullScreen }, key = "-",
{ key = "p", mods = "CTRL|SHIFT", action = wezterm.action.ActivateCommandPalette }, mods = "LEADER",
{ key = "c", mods = "CTRL|SHIFT", action = wezterm.action.CopyTo("ClipboardAndPrimarySelection") }, action = wezterm.action({ SplitPane = { direction = "Down", size = { Percent = 25 } } }),
{ key = "v", mods = "CTRL|SHIFT", action = wezterm.action.PasteFrom("Clipboard") }, },
-- move between split panes {
split_nav("move", "h"), key = "\\",
split_nav("move", "j"), mods = "LEADER",
split_nav("move", "k"), action = wezterm.action({ SplitPane = { direction = "Right", size = { Percent = 25 } } }),
split_nav("move", "l"), },
-- resize panes { key = "z", mods = "LEADER", action = "TogglePaneZoomState" },
split_nav("resize", "h"), { key = "c", mods = "LEADER", action = wezterm.action({ SpawnTab = "CurrentPaneDomain" }) },
split_nav("resize", "j"), { key = "x", mods = "LEADER", action = wezterm.action.CloseCurrentPane({ confirm = true }) },
split_nav("resize", "k"), { key = "n", mods = "LEADER", action = wezterm.action.ToggleFullScreen },
{ { key = "p", mods = "CTRL|SHIFT", action = wezterm.action.ActivateCommandPalette },
key = ",", { key = "c", mods = "CTRL|SHIFT", action = wezterm.action.CopyTo("ClipboardAndPrimarySelection") },
mods = "LEADER", { key = "v", mods = "CTRL|SHIFT", action = wezterm.action.PasteFrom("Clipboard") },
action = act.PromptInputLine({ -- move between split panes
description = "Enter new name for tab", split_nav("move", "h"),
action = wezterm.action_callback(function(window, pane, line) split_nav("move", "j"),
-- line will be `nil` if they hit escape without entering anything split_nav("move", "k"),
-- An empty string if they just hit enter split_nav("move", "l"),
-- Or the actual line of text they wrote -- resize panes
if line then split_nav("resize", "h"),
window:active_tab():set_title(line) split_nav("resize", "j"),
end split_nav("resize", "k"),
end), {
}), key = ",",
}, mods = "LEADER",
split_nav("resize", "l"), action = act.PromptInputLine({
} description = "Enter new name for tab",
action = wezterm.action_callback(function(window, pane, line)
-- line will be `nil` if they hit escape without entering anything
-- An empty string if they just hit enter
-- Or the actual line of text they wrote
if line then
window:active_tab():set_title(line)
end
end),
}),
},
split_nav("resize", "l"),
}
for i = 1, 8 do for i = 1, 8 do
-- CTRL+ALT + number to activate that tab -- CTRL+ALT + number to activate that tab
table.insert(config.keys, { table.insert(config.keys, {
key = tostring(i), key = tostring(i),
mods = "LEADER", mods = "LEADER",
action = wezterm.action.ActivateTab(i - 1), action = wezterm.action.ActivateTab(i - 1),
}) })
end end
end end
return M return M