Skip to content

Commit 6b01851

Browse files
authored
Merge pull request #25 from MLFlexer/19-add-callbacks-when-changing-workspace-session
19 add callbacks when changing workspace session
2 parents a0fa043 + d44f0ac commit 6b01851

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,26 @@ If you want your project switcher only to select projects from this list, but st
7575
```
7676

7777
#### Update right-status with the path
78-
Adding the path as a part of the right-status can be done via. [update-right-status](https://wezfurlong.org/wezterm/config/lua/window-events/update-right-status.html) event
78+
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.
7979

8080
```lua
81-
local function base_path_name(str)
82-
return string.gsub(str, "(.*[/\\])(.*)", "%2")
83-
end
84-
85-
local function update_right_status(window)
86-
local title = base_path_name(window:active_workspace())
81+
wezterm.on("smart_workspace_switcher.workspace_chosen", function(window, path)
82+
local base_path = string.gsub(path, "(.*[/\\])(.*)", "%2")
8783
window:set_right_status(wezterm.format({
88-
{ Foreground = { Color = "green" } },
89-
{ Text = title .. " " },
84+
{ Foreground = { Color = colors.colors.ansi[5] } },
85+
{ Text = base_path .. " " },
9086
}))
91-
end
87+
end)
88+
```
9289

93-
wezterm.on("update-right-status", function(window, _)
94-
update_right_status(window)
90+
#### Callbacks when switching workspace
91+
Use the `smart_workspace_switcher.workspace_chosen` event which is emitted when choosing the workspace to add a callback function.
92+
```lua
93+
wezterm.on("smart_workspace_switcher.workspace_chosen", function(window, path)
94+
wezterm.log_info("THIS IS EMITTED FROM THE CALLBACK")
9595
end)
9696
```
97+
9798
#### Workspace formatter
9899
Set a custom workspace formatter, see [Wezterm formatting docs](https://wezfurlong.org/wezterm/config/lua/wezterm/format.html)
99100

plugin/init.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ end
3030
---@param extra_args? string
3131
---@return { id: string, label: string }[]
3232
local function get_zoxide_workspaces(extra_args)
33-
if extra_args == nil then extra_args = "" end
33+
if extra_args == nil then
34+
extra_args = ""
35+
end
3436
local stdout = run_child_process(zoxide_path .. " query -l " .. extra_args)
3537

3638
local workspace_table = {}
@@ -85,6 +87,7 @@ local function workspace_switcher(extra_args)
8587
inner_pane
8688
)
8789
end
90+
wezterm.emit("smart_workspace_switcher.workspace_chosen", window, id)
8891
end
8992
end),
9093
title = "Choose Workspace",

0 commit comments

Comments
 (0)