"Life is all about sharing. If we are good at something, pass it on." - Mary Berry

Reload Helix automatically after switching from lazygit


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:

 3source wezterm-split-pane.sh
 5program=$(wezterm cli list | awk -v pane_id="$pane_id" '$3==pane_id { print $6 }')
 6if [ "$program" = "lazygit" ]; then
 7    wezterm cli activate-pane-direction down
 9    echo "lazygit" | wezterm cli send-text --pane-id $pane_id --no-paste

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:

 1wezterm.on('reload-helix', function(window, pane)
 2  local top_process = basename(pane:get_foreground_process_name())
 3  if top_process == 'hx' then
 4    local bottom_pane = pane:tab():get_pane_direction('Down')
 5    if bottom_pane ~= nil then
 6      local bottom_process = basename(bottom_pane:get_foreground_process_name())
 7      if bottom_process == 'lazygit' then
 8        local action = wezterm.action.SendString(':reload-all\r\n')
 9        window:perform_action(action, pane);
10      end
11    end
12  end

then I just need to trigger multiple actions when switching panes:

1config.keys = {
2  {
3    key = '[',
4    mods = 'CMD',
5    action = act.Multiple {
6      act.ActivatePaneDirection 'Up',
7      act.EmitEvent 'reload-helix',
8    }
9  },

With this solution, Helix will automatically reload when switching from lazygit, making the workflow more seamless and efficient.

Tags: helix wezterm

Edit on GitHub

Related Posts: