update wezterm workspace switching
a5b8b5a873919d19e3e9a956b443d3b9109c2e45
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
- Parent 1: 34998a9b80a0
bugabingas dorkfiles
a5b8b5a873919d19e3e9a956b443d3b9109c2e45
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
+97 / −20 text lines
+5 / −0 text lines
+14 / −1 text lines
local palette = require 'bugabinga.nugu.palette_dark'.palettelocal use_palette_for_scheme = function ( scheme ) palette = scheme == 'nugu-light' and nugu_light or nugu_darkendlocal use_palette_for_window = function ( window ) local ok, config = pcall( function () return window:effective_config() end ) if ok and config then use_palette_for_scheme( config.color_scheme ) endend if config then use_palette_for_scheme( config.color_scheme ) end local pi_badge, pi_badge_color = pi_state_badge( (tab.active_pane.user_vars or {}).PI_STATE ) local active_progress_badge, active_progress_color = progress_badge( tab.active_pane.progress ) use_palette_for_window( window )+78 / −19 text lines
local function add_path_element( choice_table, workspace_ids, path ) if not path or path == '' then return end local updated_path = string.gsub( path, wezterm.home_dir, '~' ) if not workspace_ids[updated_path] then table.insert( choice_table, { id = path, label = updated_path, } ) workspace_ids[updated_path] = true endend local updated_path = string.gsub( path, wezterm.home_dir, '~' ) if not workspace_ids[updated_path] then table.insert( choice_table, { id = path, label = updated_path, } ) end add_path_element( choice_table, workspace_ids, path ) end return choice_tableendlocal function get_workspace_dir_elements( choice_table, workspace_ids ) local workspace_dir = wezterm.home_dir .. '/Workspace' local stdout = run_child_process( 'find ' .. workspace_dir .. ' -mindepth 1 -maxdepth 1 -type d | sort' ) for _, path in ipairs( wezterm.split_by_newlines( stdout ) ) do add_path_element( choice_table, workspace_ids, path ) get_workspace_dir_elements( choices, workspace_ids )local function spawn_workspace_window( _window, workspace, cwd ) -- `mux.spawn_window()` and `wezterm cli spawn --new-window` create mux -- windows, which can appear in the workspace HUD without necessarily mapping -- a new OS/WM window. For the workflow-window use-case, force a fresh GUI. local args = { 'wezterm', 'start', '--always-new-process', '--workspace', workspace } if cwd then table.insert( args, '--cwd' ) table.insert( args, cwd ) end if wezterm.background_child_process then wezterm.background_child_process( args ) else local ok, err = pcall( function () wezterm.run_child_process( args ) end ) if not ok then wezterm.log_error( 'Failed to spawn workspace window: ' .. tostring( err ) ) end endendlocal function zoxide_chosen_in_new_window( window, path, label_path ) spawn_workspace_window( window, label_path, path ) -- increment zoxide path score run_child_process( zoxide_path .. ' add ' .. path )endlocal function workspace_chosen_in_new_window( window, workspace ) spawn_workspace_window( window, workspace )endlocal function switch_workspace()local function choose_workspace( title, fuzzy_description, handler ) if id and label then if workspace_exists( id ) then -- workspace is choosen workspace_chosen( inner_window, inner_pane, id ) else -- path is choosen zoxide_chosen( inner_window, inner_pane, id, label ) end end if id and label then handler( inner_window, inner_pane, id, label ) endlocal function switch_workspace() return choose_workspace( 'Choose Workspace', 'Workspace to switch: ', function ( window, pane, id, label ) if workspace_exists( id ) then workspace_chosen( window, pane, id ) else zoxide_chosen( window, pane, id, label ) end end )endlocal function switch_workspace_in_new_window() return choose_workspace( 'Choose Workspace in New Window', 'Workspace for new window: ', function ( window, pane, id, label ) if workspace_exists( id ) then workspace_chosen_in_new_window( window, id ) else zoxide_chosen_in_new_window( window, id, label ) end end )end switch_workspace_in_new_window = switch_workspace_in_new_window,