fix(terminal): wezterm nvim switch pane integration

When working on windows the top most process name is the current foreground
process name. For example if you are runing something like a terminal in nvim
the terminal process is the foreground like `nu`

This now gets the full process stack and if any of the processes in the stack
are a editor then it will send the binding to the editor to change the pane.

This now will give you windows wezterm integration for the tmux navigator
custom plugins.
This commit is contained in:
Ade Attwood 2025-07-25 09:04:41 +01:00
parent 42cbeed7de
commit adf01758f0

View file

@ -3,15 +3,44 @@ local wezterm = require "wezterm"
local scheme = wezterm.get_builtin_color_schemes() local scheme = wezterm.get_builtin_color_schemes()
local theme = scheme["Poimandres"] local theme = scheme["Poimandres"]
function collect_executables(process)
local executables = {}
if process.executable then
table.insert(executables, process.executable)
end
if process.ppid and process.ppid > 0 then
local parent_process = wezterm.procinfo.get_info_for_pid(process.ppid)
if parent_process then
local parent_executables = collect_executables(parent_process)
for _, exe in ipairs(parent_executables) do
table.insert(executables, exe)
end
end
end
return executables
end
local function matches_editor(process)
local executables = collect_executables(process)
for _, executable in ipairs(executables) do
if string.match(executable, "vim") or string.match(executable, "emacs") then
return true
end
end
return false
end
local function vim_pass_though_action(config) local function vim_pass_though_action(config)
return { return {
key = config.key, key = config.key,
mods = config.mods, mods = config.mods,
action = wezterm.action_callback(function(win, pane) action = wezterm.action_callback(function(win, pane)
local process_name = pane:get_foreground_process_name()
-- If we are in vim then we want to send the key to go to the net pain -- If we are in vim then we want to send the key to go to the net pain
if string.match(process_name, "vim") or string.match(process_name, "emacs") then if matches_editor(pane:get_foreground_process_info()) then
win:perform_action({ SendKey = { key = config.key, mods = config.mods } }, pane) win:perform_action({ SendKey = { key = config.key, mods = config.mods } }, pane)
return return
end end
@ -26,7 +55,7 @@ return {
-- You will need to install the beta version of the font to get the ligatures -- You will need to install the beta version of the font to get the ligatures
-- https://github.com/intel/intel-one-mono/issues/9#issuecomment-1994958719 -- https://github.com/intel/intel-one-mono/issues/9#issuecomment-1994958719
font = wezterm.font { font = wezterm.font {
family = "FiraCode Nerd Font Mono", family = "Hasklug Nerd Font Mono",
}, },
-- -- The nord theme to fit with everyting else -- -- The nord theme to fit with everyting else
@ -75,7 +104,7 @@ return {
audible_bell = "Disabled", audible_bell = "Disabled",
-- Have a really clean UI when there is only one tab open -- Have a really clean UI when there is only one tab open
hide_tab_bar_if_only_one_tab = false, hide_tab_bar_if_only_one_tab = true,
-- Disabled all the padding, this makes vim look a lot nicer when all the -- Disabled all the padding, this makes vim look a lot nicer when all the
-- window bars go to the edges of the terminal -- window bars go to the edges of the terminal