Reload Helix automatically after switching from lazygit
2023-07-25
Categories: Development Environment
This is a continuation of the Helix series. In the previous posts, I shared methods to:
I also have a script to call lazygit from within Helix:
#!/bin/sh
source wezterm-split-pane.sh
program=$(wezterm cli list | awk -v pane_id="$pane_id" '$3==pane_id { print $6 }')
if [ "$program" = "lazygit" ]; then
wezterm cli activate-pane-direction down
else
echo "lazygit" | wezterm cli send-text --pane-id $pane_id --no-paste
fi
Howerver, there is an issue with git gutter is not updated after committing.
To address this, I’ve come up with an automatic workaround using WezTerm’s support for custom events.
I created an event to reload Helix if we are coming back from lazygit:
wezterm.on('reload-helix', function(window, pane)
local top_process = basename(pane:get_foreground_process_name())
if top_process == 'hx' then
local bottom_pane = pane:tab():get_pane_direction('Down')
if bottom_pane ~= nil then
local bottom_process = basename(bottom_pane:get_foreground_process_name())
if bottom_process == 'lazygit' then
local action = wezterm.action.SendString(':reload-all\r\n')
window:perform_action(action, pane);
end
end
end
end)
then I just need to trigger multiple actions when switching panes:
config.keys = {
{
key = '[',
mods = 'CMD',
action = act.Multiple {
act.ActivatePaneDirection 'Up',
act.EmitEvent 'reload-helix',
}
},
With this solution, Helix will automatically reload when switching from lazygit, making the workflow more seamless and efficient.
Quan Tong