39 39 return choice_table, workspace_ids
42 +local function add_path_element( choice_table, workspace_ids, path )
43 + if not path
or path
== '' then return end 44 + local updated_path
= string.
gsub( path, wezterm.home_dir,
'~' )
45 + if not workspace_ids[updated_path]
then 46 + table.
insert( choice_table, {
48 + label = updated_path,
50 + workspace_ids[updated_path]
= true 42 54 local function get_zoxide_elements( choice_table, workspace_ids )
43 55 local stdout
= run_child_process( zoxide_path
.. ' query -l ' )
45 57 for _, path
in ipairs( wezterm.split_by_newlines( stdout ) )
do 46 - local updated_path
= string.
gsub( path, wezterm.home_dir,
'~' )
47 - if not workspace_ids[updated_path]
then 48 - table.
insert( choice_table, {
50 - label = updated_path,
58 + add_path_element( choice_table, workspace_ids, path )
63 +local function get_workspace_dir_elements( choice_table, workspace_ids )
64 + local workspace_dir
= wezterm.home_dir
.. '/Workspace' 65 + local stdout
= run_child_process(
'find ' .. workspace_dir
.. ' -mindepth 1 -maxdepth 1 -type d | sort' )
66 + for _, path
in ipairs( wezterm.split_by_newlines( stdout ) )
do 67 + add_path_element( choice_table, workspace_ids, path )
54 69 return choice_table
59 74 local _, workspace_ids
= get_workspace_elements( choices )
60 75 get_zoxide_elements( choices, workspace_ids )
76 + get_workspace_dir_elements( choices, workspace_ids )
106 +local function spawn_workspace_window( _window, workspace, cwd )
110 + local args
= {
'wezterm',
'start',
'--always-new-process',
'--workspace', workspace }
112 + table.
insert( args,
'--cwd' )
113 + table.
insert( args, cwd )
116 + if wezterm.background_child_process
then 117 + wezterm.background_child_process( args )
119 + local ok, err
= pcall(
function () wezterm.run_child_process( args )
end )
121 + wezterm.log_error(
'Failed to spawn workspace window: ' .. tostring( err ) )
126 +local function zoxide_chosen_in_new_window( window, path, label_path )
127 + spawn_workspace_window( window, label_path, path )
129 + run_child_process( zoxide_path
.. ' add ' .. path )
132 +local function workspace_chosen_in_new_window( window, workspace )
133 + spawn_workspace_window( window, workspace )
90 136 local function workspace_exists( workspace )
91 137 for _, workspace_name
in ipairs( mux.get_workspace_names() )
do 92 138 if workspace
== workspace_name
then 99 -local function switch_workspace()
145 +local function choose_workspace( title, fuzzy_description, handler )
100 146 return wezterm.action_callback(
function ( window, pane )
101 147 local choices
= get_choices()
103 149 window:perform_action(
104 150 act.InputSelector {
105 151 action = wezterm.action_callback(
function ( inner_window, inner_pane, id, label )
106 - if id
and label
then 107 - if workspace_exists( id )
then 109 - workspace_chosen( inner_window, inner_pane, id )
112 - zoxide_chosen( inner_window, inner_pane, id, label )
152 + if id
and label
then handler( inner_window, inner_pane, id, label )
end 116 - title =
'Choose Workspace',
117 155 description =
'Select a workspace and press Enter = accept, Esc = cancel, / = filter',
118 - fuzzy_description =
'Workspace to switch: ',
156 + fuzzy_description = fuzzy_description,
119 157 choices = choices,
165 +local function switch_workspace()
166 + return choose_workspace(
'Choose Workspace',
'Workspace to switch: ',
function ( window, pane, id, label )
167 + if workspace_exists( id )
then 168 + workspace_chosen( window, pane, id )
170 + zoxide_chosen( window, pane, id, label )
175 +local function switch_workspace_in_new_window()
176 + return choose_workspace(
'Choose Workspace in New Window',
'Workspace for new window: ',
function ( window, pane, id, label )
177 + if workspace_exists( id )
then 178 + workspace_chosen_in_new_window( window, id )
180 + zoxide_chosen_in_new_window( window, id, label )
128 186 switch_workspace = switch_workspace,
187 + switch_workspace_in_new_window = switch_workspace_in_new_window,