MLFlexer / smart_workspace_switcher.wezterm

A smart wezterm workspace switcher plugin inspired by joshmedeski/t-smart-tmux-session-manager
MIT License
70 stars 5 forks source link

suggested edit #2

Closed wez closed 1 year ago

wez commented 1 year ago

rather than:

https://github.com/MLFlexer/smart_workspace_switcher.wezterm/blob/31545dbf40f961bdc0854c3a78be22f60f37e977/plugin/init.lua#L4-L14

I'd suggest

local function resolve_script_path()
   for _, plugin in ipairs(wezterm.plugin.list()) do
    if plugin.url == "https://github.com/MLFlexer/smart_workspace_switcher.wezterm" then
        return plugin.plugin_dir .. "/script/workspace_switcher.sh"
    end
   end
end

wezterm.on("smart_workspace_switcher", function(window, pane)
   local path = resolve_script_path()
   if not path then 
      wezterm.log_error("workspace_switcher.sh not found")
      return
   end

rationale: logic that runs unconditionally at the file scope is run every time wezterm needs to create a lua context, which can be several times when a config is reloaded, and additional times in various timer or background processing scenarios.

It's best to defer the real work until you actually need to trigger it, hence this suggestion!

MLFlexer commented 1 year ago

Thanks for your suggestion, I agree with you reasoning and have implemented it :smile: