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:
1#!/bin/sh 2 3source wezterm-split-pane.sh 4 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 8else 9 echo "lazygit" | wezterm cli send-text --pane-id $pane_id --no-paste 10fi
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 13end)
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.
Related Posts:
- Turning Helix into an IDE with the help of WezTerm and CLI tools
- Debug Rust in Helix using lldb-vscode: display the contents of local string variables
- How to debug Rust in Helix?
- WezTerm: quickly select a command and open it in a new pane
- File tree workaround for Helix