smart_workspace_switcher.wezterm

repository·main·Indexed 42 days ago

https://github.com/mlflexer/smart_workspace_switcher.wezterm

A Wezterm plugin providing a fast, fuzzy-finding workspace switcher powered by zoxide. It allows users to jump between directories and workspaces using a single keypress. Note: This project is archived and no longer maintained.

Tokens
1.4K
Snippets
6
Records
7
Agent score
3%

What's inside smart_workspace_switcher.wezterm

  1. Install and set up smart_workspace_switcher.wezterm

    main

    To use the plugin, you must have zoxide installed on your system. Follow these steps in your wezterm.lua configuration:

    1. Require the plugin using the GitHub URL.
    2. Apply the default keybindings to your configuration object using workspace_switcher.apply_to_config(config).

    Note: This project is archived and no longer maintained.

    local wezterm = require("wezterm")
    local workspace_switcher = wezterm.plugin.require("https://github.com/MLFlexer/smart_workspace_switcher.wezterm")
    
    -- Assuming 'config' is your Wezterm configuration object
    workspace_switcher.apply_to_config(config)
  2. Configure custom keybindings for workspace switching

    main

    Instead of using apply_to_config, you can manually define keybindings in your config.keys table. Use workspace_switcher.switch_workspace() to open the switcher and workspace_switcher.switch_to_prev_workspace() to cycle to the previous workspace.

    config.keys = {
      -- ...
      -- your other keybindings
      {
        key = "s",
        mods = "LEADER",
        action = workspace_switcher.switch_workspace(),
      },
      {
        key = "S",
        mods = "LEADER",
        action = workspace_switcher.switch_to_prev_workspace(),
      }
    }
  3. Filter workspace results with extra_args

    main

    You can pass an extra_args table to switch_workspace to further filter the zoxide query. The string provided is concatenated to the command: zoxide query -l <extra_args>.

    For example, to filter results using rg (ripgrep) against a list of projects in ~/.projects, pass the pipe command as the argument.

    workspace_switcher.switch_workspace({ extra_args = " | rg -Fxf ~/.projects" })
  4. Customize the fuzzy finder choices

    main

    You can override the get_choices function to change what appears in the fuzzy finder.

    • To show only existing workspaces (and ignore zoxide results), use workspace_switcher.choices.get_workspace_elements({}).
    • To use the default behavior with custom logic, you can utilize the helper functions:
      • workspace_switcher.choices.get_workspace_elements({ id: string, label: string }[])
      • workspace_switcher.choices.get_zoxide_elements({ id: string, label: string }[], {extra_args?: string, workspace_ids?: workspace_ids}?)
    local workspace_switcher = wezterm.plugin.require("https://github.com/MLFlexer/smart_workspace_switcher.wezterm")
    workspace_switcher.get_choices = function(opts)
      -- this will ONLY show the workspace elements, NOT the Zoxide results
      return workspace_switcher.choices.get_workspace_elements({})
    end
  5. Customize workspace display with a formatter

    main

    You can define a workspace_formatter function to change how workspace labels are rendered in the UI using Wezterm's formatting API.

    workspace_switcher.workspace_formatter = function(label)
      return wezterm.format({
        { Attribute = { Italic = true } },
        { Foreground = { Color = "green" } },
        { Background = { Color = "black" } },
        { Text = "󱂬: " .. label },
      })
    end
  6. Configure workspace switcher settings

    main

    The following configuration keys are available on the workspace_switcher object:

    • default_workspace: Set a default workspace name (e.g., config.default_workspace = "~").
    • zoxide_path: Define a custom path to the zoxide executable (e.g., workspace_switcher.zoxide_path = "/path/to/zoxide").
    • workspace_formatter: A function used to format workspace labels.
    • get_choices: A function used to define the list of elements in the fuzzy finder.
  7. Handle workspace switcher events

    main

    The plugin emits several events that you can listen to using wezterm.on. This allows you to trigger custom logic (like updating status bars or logging) when the switcher is interacted with.

    Available Events:

    • smart_workspace_switcher.workspace_switcher.start: Fuzzy finder starts.
    • smart_workspace_switcher.workspace_switcher.canceled: No element chosen.
    • smart_workspace_switcher.workspace_switcher.selected: An element is selected.
    • smart_workspace_switcher.workspace_switcher.created: After creating and switching to a new workspace.
    • smart_workspace_switcher.workspace_switcher.chosen: After switching to a workspace.
    • smart_workspace_switcher.workspace_switcher.switched_to_prev: After switching to a previous workspace.

    Important Note on Object Types:

    • created and chosen events emit MuxWindow objects.
    • All other events emit GuiWindow objects.
    -- Example: Logging when a workspace is chosen
    wezterm.on("smart_workspace_switcher.workspace_switcher.chosen", function(window, workspace)
      wezterm.log_info("THIS IS EMITTED FROM THE CALLBACK")
    end)