Skip to content

A smart wezterm workspace switcher plugin inspired by joshmedeski/t-smart-tmux-session-manager

License

Notifications You must be signed in to change notification settings

MLFlexer/smart_workspace_switcher.wezterm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 

Repository files navigation

smart_workspace_switcher.wezterm

A smart Wezterm workspace switcher inspired by t-smart-tmux-session-manager and its successor sesh

Usage

💨 Level up your workflow by switching between workspaces ⚡ BLAZINGLY FAST ⚡ with 1️⃣ keypress, the power of fuzzy finding and zoxide! 💨

Demo gif

Dependencies

  • zoxide

Setup

  1. require the plugin:

    local wezterm = require("wezterm")
    local workspace_switcher = wezterm.plugin.require("https://github.com/MLFlexer/smart_workspace_switcher.wezterm")
  2. Apply default keybinding to config:

    workspace_switcher.apply_to_config(config)

Or make your own keybinding, see Configuration - Keybinding

Configuration:

Keybinding

Add custom keybinding

config.keys = {
  -- ...
  -- your other keybindings
  {
  key = "s",
  mods = "ALT",
  action = workspace_switcher.switch_workspace(),
  }
}

Changing default workspace name

config.default_workspace = "~"

Additional filtering

Users may also choose to include extra_args in the call to switch_workspace. The string contents of this value are appended to the call to zoxide query -l. This can be used to further filter the results of the query. For example, imagine one has a predefined list of projects from which they wish to select. It might be a file, ~/.projects, with contents like:

/Users/you/projects/gitlab.com/foo/bar
/Users/you/projects/github.com/MLFlexer/smart_workspace_switcher.wezterm

If you want your project switcher only to select projects from this list, but still make use of the zoxide query ordering, you can call the plugin as:

config.keys = {
  -- ...
  -- your other keybindings
  {
  key = "s",
  mods = "ALT",
  action = workspace_switcher.switch_workspace(" | rg -Fxf ~/.projects"),
  }
}

Update right-status with the path

Adding the path as a part of the right-status can be done with the smart_workspace_switcher.workspace_chosen event which is emitted when choosing the workspace.

wezterm.on("smart_workspace_switcher.workspace_chosen", function(window, path)
  local base_path = string.gsub(path, "(.*[/\\])(.*)", "%2")
  window:set_right_status(wezterm.format({
    { Foreground = { Color = colors.colors.ansi[5] } },
    { Text = base_path .. "  " },
  }))
end)

Callbacks when switching workspace

Use the smart_workspace_switcher.workspace_chosen event which is emitted when choosing the workspace to add a callback function.

wezterm.on("smart_workspace_switcher.workspace_chosen", function(window, path)
  wezterm.log_info("THIS IS EMITTED FROM THE CALLBACK")
end)

Workspace formatter

Set a custom workspace formatter, see Wezterm formatting docs

workspace_switcher.set_workspace_formatter(function(label)
  return wezterm.format({
    { Attribute = { Italic = true } },
    { Foreground = { Color = "green" } },
    { Background = { Color = "black" } },
    { Text = "󱂬: " .. label },
  })
end)

Zoxide path

Define path to zoxide:

workspace_switcher.set_zoxide_path("/path/to/zoxide)

About

A smart wezterm workspace switcher plugin inspired by joshmedeski/t-smart-tmux-session-manager

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages