### setup Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Initializes the plugin with optional configuration settings. ```APIDOC ## setup(opts) ### Description Initializes the plugin and sets configuration options. If `tabsets_dir` is not specified, it defaults to `~/.config/wezterm/tabsets.wezterm`. ### Signature `function M.setup(opts: TabsetOptions | nil): nil` ### Parameters - **opts** (TabsetOptions | nil) - Optional - Configuration options table. ``` -------------------------------- ### Initialize with default configuration Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/configuration.md Use this minimal setup to apply all default plugin settings. ```lua local tabsets = wezterm.plugin.require("https://github.com/srackham/tabsets.wezterm") tabsets.setup() ``` -------------------------------- ### Example TabsetTabData instances Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/types.md Examples of TabsetTabData structures for single and multiple pane configurations. ```lua { title = "Development", panes = { { left = 0, cwd = "file:///home/user/projects", exe = "/bin/bash" } } } ``` ```lua { title = "Split Windows", panes = { { left = 0, cwd = "file:///home/user", exe = "/bin/bash" }, { left = 640, cwd = "file:///home/user", exe = "/bin/vim" } } } ``` -------------------------------- ### Configure tabsets plugin Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/types.md Examples for initializing the plugin with default or custom settings. ```lua local tabsets = wezterm.plugin.require("https://github.com/srackham/tabsets.wezterm") tabsets.setup({ tabsets_dir = wezterm.config_dir .. "/tabsets.wezterm", restore_colors = false, restore_dimensions = false, fuzzy_selector = false, }) ``` ```lua tabsets.setup({ tabsets_dir = wezterm.config_dir .. "/my_tabsets", restore_colors = true, restore_dimensions = true, fuzzy_selector = true, }) ``` -------------------------------- ### Initialize tabsets plugin with setup function Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/configuration.md The setup function must be called before using other plugin features to initialize state and configuration. ```lua function M.setup(opts: TabsetOptions | nil): nil ``` -------------------------------- ### Verify tabsets setup Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/errors.md Check if the tabsets directory was created successfully after calling setup. ```lua tabsets.setup({ tabsets_dir = custom_dir }) if not fs.is_directory(custom_dir) then log_error("Tabsets directory creation failed") end ``` -------------------------------- ### Create InputSelectorChoice examples Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/types.md Examples of creating single and multiple choice objects for the input selector. ```lua { id = "development", label = "development" -- Note: label is the display field, id is the selection value } ``` ```lua { { id = "development", label = "development" }, { id = "production", label = "production" }, { id = "testing", label = "testing" } } ``` -------------------------------- ### setup(opts) Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/configuration.md Initializes the tabsets plugin with optional configuration settings. This function must be called before using any other plugin functionality. ```APIDOC ## function M.setup(opts: TabsetOptions | nil) ### Description Initializes the plugin state, creates the tabsets directory if needed, and stores the configuration options. This must be called before using any other plugin functions. ### Parameters #### Options (opts) - **tabsets_dir** (string) - Optional - Path to the directory containing tabset JSON files. Defaults to `wezterm.config_dir .. "/tabsets.wezterm"`. - **restore_colors** (boolean) - Optional - When loading a tabset into an empty window, restore the custom colors from the saved tabset. Defaults to `false`. - **restore_dimensions** (boolean) - Optional - When loading a tabset into an empty window, restore the window dimensions from the saved tabset. Defaults to `false`. - **fuzzy_selector** (boolean) - Optional - Enable fuzzy matching in the interactive tabset selector dialogs. Defaults to `false`. ### Usage Example ```lua local tabsets = wezterm.plugin.require("https://github.com/srackham/tabsets.wezterm") tabsets.setup({ tabsets_dir = wezterm.config_dir .. "/my_custom_tabsets", restore_colors = true, restore_dimensions = true, fuzzy_selector = true }) ``` ``` -------------------------------- ### Example TabsetPaneData instances Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/types.md Examples of TabsetPaneData structures for shell and non-shell executables. ```lua { left = 0, cwd = "file:///home/user/projects/myapp", exe = "/bin/bash" } ``` ```lua { left = 640, cwd = "file:///home/user/projects", exe = "/usr/bin/vim" } ``` -------------------------------- ### Importing the fs module Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Required setup to access filesystem helper utilities. ```lua local fs = require "tabsets.fs" ``` -------------------------------- ### Define Plugin Configuration State Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/architecture.md The M.options table stores plugin settings populated during setup and persists throughout the WezTerm session. ```lua M.options = { tabsets_dir = string, -- Path to tabsets directory restore_colors = boolean, -- Restore colors on load restore_dimensions = boolean, -- Restore window size on load fuzzy_selector = boolean, -- Enable fuzzy name matching } ``` -------------------------------- ### Tabset JSON Configuration Structure Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/configuration.md Example of a complete tabset configuration file defining window dimensions, colors, and tab/pane layouts. ```json { "window_width": 1920, "window_height": 1080, "colors": { "foreground": "#c0c0c0", "background": "#0c0c0c" }, "tabs": [ { "title": "Development", "panes": [ { "left": 0, "cwd": "file:///home/user/projects/myapp", "exe": "/bin/bash" } ] }, { "title": "Build", "panes": [ { "left": 0, "cwd": "file:///home/user/projects/myapp", "exe": "/bin/bash" }, { "left": 960, "cwd": "file:///home/user/projects", "exe": "/usr/bin/vim" } ] } ] } ``` -------------------------------- ### Tabset JSON Serialization Example Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/types.md Represents the structure of a serialized .tabset.json file. ```json { "window_width": 1280, "window_height": 720, "colors": { ... }, "tabs": [ { "title": "Development", "panes": [ { "left": 0, "cwd": "file:///home/user/projects/myapp", "exe": "/bin/bash" } ] } ] } ``` -------------------------------- ### Use LogAndNotifyOpts for notifications Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/types.md Examples of triggering informational and error notifications using log_and_notify. ```lua log_and_notify(window, "Tabset loaded 'development'.") -- Logs: "tabsets.wezterm: Tabset loaded 'development'." -- Toast: "Tabset loaded 'development'." ``` ```lua log_and_notify(window, "Invalid tabset name 'my@tabset'.", { error = true }) -- Logs: "tabsets.wezterm: Invalid tabset name 'my@tabset'." -- Toast: "FAILED: Invalid tabset name 'my@tabset'." ``` -------------------------------- ### Handle invalid tabset name Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/errors.md Example of checking name validity within a custom save function. ```lua -- In a custom tabset save function if not is_valid_tabset_name(name) then wezterm.log_error("Invalid name: " .. name) return false end ``` -------------------------------- ### Initialize with custom directory and all features Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/configuration.md Combine a custom storage path with all available plugin features enabled. ```lua local tabsets = wezterm.plugin.require("https://github.com/srackham/tabsets.wezterm") tabsets.setup({ tabsets_dir = os.getenv("HOME") .. "/.cache/wezterm/tabsets", restore_colors = true, restore_dimensions = true, fuzzy_selector = true, }) ``` -------------------------------- ### Initialize tabsets plugin Source: https://github.com/srackham/tabsets.wezterm/blob/main/README.md Load the plugin and apply configuration settings within the wezterm.lua file. ```lua local tabsets = wezterm.plugin.require("https://github.com/srackham/tabsets.wezterm") tabsets.setup({ -- Optional configuration options showing the default values -- Restore custom colors when loading empty window restore_colors = false, -- Restore window dimensions when loading empty window restore_dimensions = false, -- Path to the directory containing tabset JSON files tabsets_dir = wezterm.config_dir .. "/tabsets.wezterm" -- Fuzzy-match tabset name selection fuzzy_selector = false, }) ``` -------------------------------- ### Create directory with fs.mkdir Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Creates a directory and any missing parent directories using POSIX mkdir -p. Returns true on success and false on failure. ```lua local fs = require "tabsets.fs" if fs.mkdir("/home/user/.config/wezterm/tabsets.wezterm") then print("Tabsets directory created") end ``` ```lua if not fs.mkdir(dir) then log_error("Failed to create tabsets directory '" .. dir .. "'.") return false end ``` -------------------------------- ### Initialize with all features enabled Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/configuration.md Enable color restoration, dimension restoration, and fuzzy matching for the selector dialogs. ```lua local tabsets = wezterm.plugin.require("https://github.com/srackham/tabsets.wezterm") tabsets.setup({ restore_colors = true, restore_dimensions = true, fuzzy_selector = true, }) ``` -------------------------------- ### Initialize tabsets plugin Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Configures the plugin directory and behavior. Defaults to ~/.config/wezterm/tabsets.wezterm if no directory is provided. ```lua local tabsets = wezterm.plugin.require("https://github.com/srackham/tabsets.wezterm") tabsets.setup() ``` ```lua local tabsets = wezterm.plugin.require("https://github.com/srackham/wezterm-tabsets") tabsets.setup({ tabsets_dir = wezterm.config_dir .. "/my_tabsets", restore_colors = true, restore_dimensions = true, fuzzy_selector = true, }) ``` -------------------------------- ### Initialize with custom directory Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/configuration.md Specify a custom path for storing tabset JSON files using the tabsets_dir option. ```lua local tabsets = wezterm.plugin.require("https://github.com/srackham/tabsets.wezterm") tabsets.setup({ tabsets_dir = wezterm.config_dir .. "/my_custom_tabsets" }) ``` -------------------------------- ### fs.mkdir(path: string): boolean Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Creates a directory and any missing parent directories using the POSIX mkdir -p command. ```APIDOC ## fs.mkdir(path: string): boolean ### Description Creates a directory and any missing parent directories. Does not fail if the directory already exists. ### Parameters - **path** (string) - Required - Path to directory to create ### Return Type - **boolean** - true on success, false on failure ### Example ```lua local fs = require "tabsets.fs" if fs.mkdir("/home/user/.config/wezterm/tabsets.wezterm") then print("Tabsets directory created") end ``` ``` -------------------------------- ### Import tabsets plugin Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Required initialization step to load the plugin module. ```lua local tabsets = wezterm.plugin.require("https://github.com/srackham/tabsets.wezterm") ``` -------------------------------- ### Recover from directory creation failure Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/errors.md Check for directory existence and write permissions before initializing the plugin. ```lua -- Check if directory exists and is writable before setup local fs = require "tabsets.fs" local parent = os.getenv("HOME") .. "/.config/wezterm" if not fs.is_directory(parent) then log_error("Parent directory does not exist") return end ``` -------------------------------- ### Configure Window State Restoration Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/README.md Enable restoration of colors and dimensions when loading a tabset into an empty window. ```lua tabsets.setup({ restore_colors = true, restore_dimensions = true, }) ``` -------------------------------- ### Handle optional operations with pcall Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/errors.md Wrap user-initiated operations in pcall to prevent configuration crashes. ```lua wezterm.on("load_tabset", function(window) pcall(function() tabsets.load_tabset(window) end) end) ``` -------------------------------- ### Verify file existence before loading Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/errors.md Use this check to prevent errors when a tabset file is missing. ```lua -- Verify file exists before loading if not fs.is_file(file_path) then log_and_notify(window, "Tabset not found", { error = true }) return end ``` -------------------------------- ### Configure Tabsets Directory Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/configuration.md Sets the directory path for storing tabsets during plugin initialization. ```lua tabsets.setup({ tabsets_dir = wezterm.config_dir .. "/tabsets.wezterm" }) -- If ~/.config/wezterm/tabsets.wezterm does not exist, it is created ``` -------------------------------- ### tabset_action(window, callback, prompt) Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/internal-helpers.md Presents an interactive input selector dialog to the user for choosing a tabset. Upon selection, the provided callback is executed with the selected tabset ID. ```APIDOC ## tabset_action(window, callback, prompt) ### Description Helper function that collects available tabset names and presents them to the user via an interactive input selector dialog. When the user selects a tabset, the provided callback is invoked with the selected tabset name as the `id` parameter. ### Parameters - **window** (`wezterm.window`) - Required - Active WezTerm window - **callback** (`function`) - Required - Callback invoked as `callback(window, pane, id)` when user selects a tabset - **prompt** (`string`) - Optional - Prompt text to display in the selector ### Example ```lua tabset_action(window, function(_, _, tabset_name) if tabset_name then M.load_tabset_by_name(window, tabset_name) end end, "Select tabset to load:") ``` ``` -------------------------------- ### Configure tabset key bindings Source: https://github.com/srackham/tabsets.wezterm/blob/main/README.md Define events and key mappings to trigger tabset operations via the WezTerm configuration builder. ```lua wezterm.on("save_tabset", function(window) tabsets.save_tabset(window) end) wezterm.on("load_tabset", function(window) tabsets.load_tabset(window) end) wezterm.on("delete_tabset", function(window) tabsets.delete_tabset(window) end) wezterm.on("rename_tabset", function(window) tabsets.rename_tabset(window) end) for _, v in ipairs({ { key = "S", mods = "LEADER|SHIFT", action = wezterm.action { EmitEvent = "save_tabset" } }, { key = "L", mods = "LEADER|SHIFT", action = wezterm.action { EmitEvent = "load_tabset" } }, { key = "D", mods = "LEADER|SHIFT", action = wezterm.action { EmitEvent = "delete_tabset" } }, { key = "R", mods = "LEADER|SHIFT", action = wezterm.action { EmitEvent = "rename_tabset" } }, }) do table.insert(config.keys, v) end ``` -------------------------------- ### Handle Missing Tabset Files Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/errors.md Verify that the tabset list is not empty before attempting to load to prevent errors when no files are found. ```lua -- Guide user to save a tabset first if #choices == 0 then log_and_notify(window, "No tabsets to load. Save one first.", { error = true }) return end ``` -------------------------------- ### Handle Directory Access Errors Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/errors.md Use pcall to safely check for directory existence and permissions before performing file operations. ```lua -- Verify directory exists before attempting to read local ok, files = pcall(wezterm.read_dir, M.options.tabsets_dir) if not ok then log_and_notify(window, "Cannot access tabsets directory", { error = true }) return end ``` -------------------------------- ### Handle Tab Creation Failures Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/errors.md Validate working directory accessibility and provide a fallback to the home directory when spawning new tabs. ```lua -- Check that working directories are accessible local cwd_path = extract_path_from_uri(cwd_uri) if not fs.is_directory(cwd_path) then -- Use home directory as fallback cwd_path = os.getenv("HOME") end new_tab = window:mux_window():spawn_tab { cwd = cwd_path } ``` -------------------------------- ### Define Tabset File Path Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/configuration.md The standard naming convention for tabset configuration files. ```text {tabsets_dir}/{name}.tabset.json ``` -------------------------------- ### Handle existing target during rename Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/errors.md Check for existing files to prompt the user for confirmation or a different name. ```lua -- Prompt user to confirm overwrite or choose different name if fs.is_path(target_file) then -- Suggest different name or require confirmation return false end ``` -------------------------------- ### Construct Tabset File Path Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/internal-helpers.md Generates the full filesystem path for a tabset file based on its logical name and configured directory. ```lua local function tabset_file(name: string): string ``` ```lua return M.options.tabsets_dir .. "/" .. name .. ".tabset.json" ``` ```lua M.options.tabsets_dir = "/home/user/.config/wezterm/tabsets.wezterm" local path = tabset_file("development") -- Returns: "/home/user/.config/wezterm/tabsets.wezterm/development.tabset.json" local path2 = tabset_file("my_workspace") -- Returns: "/home/user/.config/wezterm/tabsets.wezterm/my_workspace.tabset.json" ``` -------------------------------- ### Project Directory Structure Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/README.md Visual representation of the plugin's file organization. ```text plugin/ ├── init.lua # Main plugin module (exported API) └── tabsets/ └── fs.lua # Filesystem utilities module ``` -------------------------------- ### Handle Executable Resolution Failures Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/errors.md Silently skip unavailable executables and fall back to the default shell. ```lua -- Silently skip non-shell executables that cannot be resolved local exe = resolve_executable(pane_data.exe) if not exe then -- Pane will open with shell instead log_info("Using default shell instead of unavailable executable") goto continue end ``` -------------------------------- ### Integrate with Command Palette Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/configuration.md Adds tabset management commands to the WezTerm command palette. ```lua local palette_commands = {} for _, v in ipairs({ { brief = "Tabset: Save", icon = "md_content_save", action = wezterm.action_callback(tabsets.save_tabset), }, { brief = "Tabset: Load", icon = "cod_terminal_tmux", action = wezterm.action_callback(tabsets.load_tabset), }, { brief = "Tabset: Delete", icon = "md_delete", action = wezterm.action_callback(tabsets.delete_tabset), }, { brief = "Tabset: Rename", icon = "md_rename_box", action = wezterm.action_callback(tabsets.rename_tabset), }, }) do table.insert(palette_commands, v) end wezterm.on("augment-command-palette", function() return palette_commands end) ``` -------------------------------- ### Verify directory accessibility before saving Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/errors.md Check that the target directory exists and is writable before attempting to save a file. ```lua -- Ensure directory exists and is writable before saving if not fs.is_directory(M.options.tabsets_dir) then log_error("Tabsets directory does not exist") return false end ``` -------------------------------- ### fs.which Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Resolves a command name to its absolute path using the system PATH. ```APIDOC ## fs.which(command: string) ### Description Resolves a command name to its absolute path by searching standard system paths defined in the PATH environment variable. ### Parameters - **command** (string) - Required - Command name to resolve ### Return Type - **string | nil** - Absolute path to the command if found, nil otherwise ### Example ```lua local fs = require "tabsets.fs" local bash_path = fs.which("bash") if bash_path then print("Bash found at: " .. bash_path) end ``` ``` -------------------------------- ### Plugin Module Path Configuration Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/configuration.md The plugin automatically updates the Lua package path to include the plugin directory, enabling the filesystem module. ```lua {plugin_dir}/plugin/?.lua {plugin_dir}/plugin/?/init.lua ``` ```lua local fs = require "tabsets.fs" ``` -------------------------------- ### Resolve command path with fs.which Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Locates executables using the system PATH. Returns nil if the command is not found. ```lua local fs = require "tabsets.fs" local bash_path = fs.which("bash") if bash_path then print("Bash found at: " .. bash_path) end ``` ```lua local notify_send = fs.which("notify-send") if notify_send then -- Use notify-send for notifications else -- Use WezTerm toast notifications as fallback end ``` -------------------------------- ### Configure tabset palette commands Source: https://github.com/srackham/tabsets.wezterm/blob/main/README.md Register tabset actions into the WezTerm command palette using the augment-command-palette event. ```lua -- Palette commands are accumulated in this table and then installed with the "augment-command-palette" event local palette_commands = {} -- Add tabsets Palette bindings for _, v in ipairs({ { brief = "Tabset: Save", icon = "md_content_save", action = wezterm.action_callback(tabsets.save_tabset), }, { brief = "Tabset: Load", icon = "cod_terminal_tmux", action = wezterm.action_callback(tabsets.load_tabset), }, { brief = "Tabset: Delete", icon = "md_delete", action = wezterm.action_callback(tabsets.delete_tabset), }, { brief = "Tabset: Rename", icon = "md_rename_box", action = wezterm.action_callback(tabsets.rename_tabset), }, }) do table.insert(palette_commands, v) end -- Install Palette commands wezterm.on("augment-command-palette", function() return palette_commands end) ``` -------------------------------- ### Load tabset by name Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Directly load a tabset by its logical name or via a custom event handler. ```lua local tabsets = wezterm.plugin.require("https://github.com/srackham/tabsets.wezterm") tabsets.setup() tabsets.load_tabset_by_name(window, "development") ``` ```lua wezterm.on("load_dev_tabset", function(window) tabsets.load_tabset_by_name(window, "development") end) table.insert(config.keys, { key = "D", mods = "LEADER", action = wezterm.action { EmitEvent = "load_dev_tabset" }, }) ``` -------------------------------- ### Log and notify user Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/internal-helpers.md Logs a message and triggers a desktop notification, optionally marking it as an error. ```lua -- Success notification log_and_notify(window, "Tabset saved 'development'.") -- Error notification log_and_notify(window, "Invalid tabset name", { error = true }) ``` -------------------------------- ### Checking path existence with fs.is_path Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Verifies if a path exists as any file or directory type using POSIX test -e. ```lua local fs = require "tabsets.fs" if fs.is_path("/home/user/.config") then print("Config directory exists") end ``` ```lua if not fs.is_path(config_file) then print("Config file not found") return false end ``` -------------------------------- ### log_and_notify(window, message, opts) Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/internal-helpers.md Logs a message and displays it as a desktop notification, with support for error-specific formatting. ```APIDOC ## log_and_notify(window, message, opts) ### Description Logs a message and displays it as a desktop notification. If `opts.error` is `true`, the message is logged as an error and prefixed with "FAILED:" in the notification. ### Parameters - **window** (`wezterm.window`) - Required - Active WezTerm window - **message** (`string`) - Required - Message text to display and log - **opts** (`LogAndNotifyOpts`) - Optional - Optional notification options ### Example ```lua -- Success notification log_and_notify(window, "Tabset saved 'development'.") -- Error notification log_and_notify(window, "Invalid tabset name", { error = true }) ``` ``` -------------------------------- ### retrieve_tabset_data(window) Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/internal-helpers.md Captures the complete state of the current window, including dimensions, colors, tabs, and panes. ```APIDOC ## retrieve_tabset_data(window) ### Description Captures the complete state of the current window, including dimensions, colors, tabs, and panes. Iterates over all tabs in the window's mux window, and for each tab, iterates over all panes collecting their metadata. ### Signature `local function retrieve_tabset_data(window: wezterm.window): TabsetData` ### Parameters - **window** (wezterm.window) - Required - Active WezTerm window to capture ### Returns - **TabsetData** - Captured tabset data ``` -------------------------------- ### Add Tabset Commands to Palette Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/README.md Define command palette entries and register them via the augment-command-palette event. ```lua local palette_commands = {} for _, v in ipairs({ { brief = "Tabset: Save", icon = "md_content_save", action = wezterm.action_callback(tabsets.save_tabset) }, { brief = "Tabset: Load", icon = "cod_terminal_tmux", action = wezterm.action_callback(tabsets.load_tabset) }, { brief = "Tabset: Delete", icon = "md_delete", action = wezterm.action_callback(tabsets.delete_tabset) }, { brief = "Tabset: Rename", icon = "md_rename_box", action = wezterm.action_callback(tabsets.rename_tabset) }, }) do table.insert(palette_commands, v) end wezterm.on("augment-command-palette", function() return palette_commands end) ``` -------------------------------- ### Bind WezTerm Events Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/configuration.md Registers event handlers for saving, loading, deleting, and renaming tabsets. ```lua local tabsets = wezterm.plugin.require("https://github.com/srackham/tabsets.wezterm") tabsets.setup() wezterm.on("save_tabset", function(window) tabsets.save_tabset(window) end) wezterm.on("load_tabset", function(window) tabsets.load_tabset(window) end) wezterm.on("delete_tabset", function(window) tabsets.delete_tabset(window) end) wezterm.on("rename_tabset", function(window) tabsets.rename_tabset(window) end) ``` -------------------------------- ### log_and_notify(window, message, opts) Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/types.md Logs a message to the WezTerm logs and displays a notification to the user. The behavior can be customized via the LogAndNotifyOpts parameter. ```APIDOC ## log_and_notify(window, message, opts) ### Description Logs a message to the WezTerm logs and displays a notification to the user. If the error option is enabled, the message is logged as an error and prefixed with 'FAILED:'. ### Parameters - **window** (wezterm.window) - Required - The current WezTerm window instance. - **message** (string) - Required - The message to log and display. - **opts** (LogAndNotifyOpts) - Optional - Configuration options for the notification. ### LogAndNotifyOpts Fields - **error** (boolean) - Optional - If true, logs as an error and prefixes the notification with 'FAILED:'. Defaults to false. ### Example ```lua -- Informational notification log_and_notify(window, "Tabset loaded 'development'.") -- Error notification log_and_notify(window, "Invalid tabset name.", { error = true }) ``` ``` -------------------------------- ### Handle Pane Creation Failures Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/errors.md Check the result of a split operation and skip the pane creation if it fails to prevent further errors. ```lua -- Gracefully skip pane creation and continue new_pane = new_tab:active_pane():split { direction = direction, cwd = cwd } if not new_pane then log_error("Pane creation failed, skipping") goto continue end ``` -------------------------------- ### Verifying regular files with fs.is_file Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Confirms if a path is a regular file using POSIX test -f, excluding directories and special files. ```lua local fs = require "tabsets.fs" if fs.is_file("/home/user/tabsets/default.tabset.json") then print("Tabset file found") end ``` ```lua if not fs.is_file(file_path) then log_error("Path is not a regular file") return false end ``` -------------------------------- ### Implement Graceful Error Handling Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/architecture.md Use this pattern to catch operation failures and notify the user via toast notifications instead of crashing the terminal. ```lua local function operation() -- Attempt operation local ok = some_operation() if not ok then log_and_notify(window, "Operation failed", { error = true }) return false -- Return failure, don't throw end return true end ``` -------------------------------- ### Invoke tabset selection dialog Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/internal-helpers.md Presents an interactive selector for tabsets and executes a callback upon selection. ```lua tabset_action(window, function(_, _, tabset_name) if tabset_name then M.load_tabset_by_name(window, tabset_name) end end, "Select tabset to load:") ``` -------------------------------- ### Load saved tabset Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Displays a selector to load a previously saved tab layout. Appends tabs to the current window. ```lua wezterm.on("load_tabset", function(window) tabsets.load_tabset(window) end) table.insert(config.keys, { key = "L", mods = "LEADER|SHIFT", action = wezterm.action { EmitEvent = "load_tabset" }, }) ``` ```lua table.insert(palette_commands, { brief = "Tabset: Load", icon = "cod_terminal_tmux", action = wezterm.action_callback(tabsets.load_tabset), }) ``` -------------------------------- ### fs.mv(src_path: string, dst_path: string): boolean Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Renames or moves a file or directory using the POSIX mv command. ```APIDOC ## fs.mv(src_path: string, dst_path: string): boolean ### Description Renames or moves a file or directory. Works across filesystems. ### Parameters - **src_path** (string) - Required - Source path to move - **dst_path** (string) - Required - Destination path ### Return Type - **boolean** - true on success, false on failure ### Example ```lua local fs = require "tabsets.fs" if fs.mv("/home/user/.config/wezterm/tabsets.wezterm/old.tabset.json", "/home/user/.config/wezterm/tabsets.wezterm/new.tabset.json") then print("Tabset renamed") end ``` ``` -------------------------------- ### load_tabset Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Interactively selects and loads a saved tabset into the current window. ```APIDOC ## load_tabset(window) ### Description Displays an interactive selector for available tabset files. Loads and recreates the selected tab layout in the current window. ### Signature `function M.load_tabset(window: wezterm.window): nil` ### Parameters - **window** (wezterm.window) - Required - The active WezTerm window. ``` -------------------------------- ### Save current tabset Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Captures the current window layout and saves it to a JSON file. Requires a valid alphanumeric name. ```lua wezterm.on("save_tabset", function(window) tabsets.save_tabset(window) end) table.insert(config.keys, { key = "S", mods = "LEADER|SHIFT", action = wezterm.action { EmitEvent = "save_tabset" }, }) ``` ```lua local palette_commands = {} table.insert(palette_commands, { brief = "Tabset: Save", icon = "md_content_save", action = wezterm.action_callback(tabsets.save_tabset), }) ``` -------------------------------- ### fs.is_executable(path: string): boolean Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Checks whether a path exists and has executable permission. ```APIDOC ## fs.is_executable(path: string): boolean ### Description Checks whether a path exists and is executable. Returns true if the path exists and the current user has execute permission on it. ### Parameters - **path** (string) - Required - Filesystem path to check ### Return Type boolean ``` -------------------------------- ### Extract path from URI Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/internal-helpers.md Strips the file:// prefix from a URI string to return a local filesystem path. ```lua local function extract_path_from_uri(uri: string): string ``` ```lua return (uri:gsub("^file://", "")) ``` ```lua local path = extract_path_from_uri("file:///home/user/projects") -- Returns: "/home/user/projects" local path2 = extract_path_from_uri("file:///home/user/with space/dir") -- Returns: "/home/user/with space/dir" local path3 = extract_path_from_uri("file:///root") -- Returns: "/root" ``` -------------------------------- ### Enable Fuzzy Matching Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/README.md Enable the fuzzy selector to allow partial name matching when selecting tabsets. ```lua tabsets.setup({ fuzzy_selector = true, }) ``` -------------------------------- ### Validate JSON structure before loading Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/errors.md Ensure the file content is valid JSON and contains the expected tabs structure. ```lua -- Validate JSON structure before loading local data = wezterm.json_parse(file_content) if not data or not data.tabs then log_and_notify(window, "Invalid tabset file", { error = true }) return false end ``` -------------------------------- ### Update Lua package path Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/internal-helpers.md Registers the plugin directory in package.path to allow module imports. ```lua if not update_plugin_path("tabsets.wezterm") then return {} end ``` -------------------------------- ### fs.basename(s: string): string Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Extracts the final path component from a filesystem path using string manipulation. ```APIDOC ## fs.basename(s: string): string ### Description Extracts the basename (final path component) from a filesystem path. Handles both POSIX (/) and Windows (\) path separators. ### Parameters - **s** (string) - Required - Full filesystem path ### Return Type - **string** - The final path component ### Example ```lua local fs = require "tabsets.fs" local filename = fs.basename("/home/user/.config/wezterm/tabsets.wezterm/default.tabset.json") -- Returns: "default.tabset.json" ``` ``` -------------------------------- ### update_plugin_path(plugin_url) Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/internal-helpers.md Updates Lua's package.path to include the plugin's module directory, allowing for module loading. ```APIDOC ## update_plugin_path(plugin_url) ### Description Updates Lua's `package.path` to include the plugin's module directory, enabling the use of `require "tabsets.fs"` to load the filesystem submodule. This function searches the WezTerm plugin registry for a plugin whose URL contains the provided `plugin_url` string. ### Parameters - **plugin_url** (`string`) - Required - Partial or full plugin URL to match ### Returns - **boolean** - `true` if the plugin was found and path updated, `false` otherwise ### Example ```lua if not update_plugin_path("tabsets.wezterm") then return {} end ``` ``` -------------------------------- ### Remove empty directories with fs.rmdir Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Removes an empty directory using the POSIX rmdir command. Fails if the directory is not empty or does not exist. ```lua local fs = require "tabsets.fs" if fs.rmdir("/home/user/empty_dir") then print("Empty directory removed") else print("Directory not empty or does not exist") end ``` -------------------------------- ### Checking directories with fs.is_directory Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Validates if a path exists and is a directory using POSIX test -d. ```lua local fs = require "tabsets.fs" if not fs.is_directory("/home/user/.config/wezterm/tabsets.wezterm") then print("Tabsets directory not found") end ``` ```lua if fs.is_directory(path) then -- Process directory else log_error("Path is not a directory") end ``` -------------------------------- ### Capture window state with retrieve_tabset_data Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/internal-helpers.md Captures the current window's dimensions, colors, tabs, and pane metadata into a TabsetData structure. ```lua local tabset_data = retrieve_tabset_data(window) -- Returns a TabsetData structure with: -- tabset_data.window_width = 1280 -- tabset_data.window_height = 720 -- tabset_data.colors = { ... } -- tabset_data.tabs = [ ... ] ``` -------------------------------- ### fs.is_path(path: string): boolean Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Checks whether a filesystem path exists as any type of file or directory. ```APIDOC ## fs.is_path(path: string): boolean ### Description Checks whether a filesystem path exists. Returns true if the path exists as any type of file or directory, false otherwise. ### Parameters - **path** (string) - Required - Filesystem path to check ### Return Type boolean ``` -------------------------------- ### Read and parse data with load_from_json_file Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/internal-helpers.md Reads a JSON file from the filesystem and parses it into a Lua table. Returns nil if the file is missing or invalid. ```lua local data = load_from_json_file("/home/user/.config/wezterm/tabsets.wezterm/dev.tabset.json") if not data then log_and_notify(window, "Tabset file not found", { error = true }) return end ``` -------------------------------- ### Log informational messages Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/internal-helpers.md Logs messages to the WezTerm console with a plugin-specific prefix. ```lua local function log_info(message: string): nil ``` ```lua wezterm.log_info(plugin_name .. ": " .. message) ``` ```lua log_info("Tabset loaded 'development'.") -- WezTerm log: "tabsets.wezterm: Tabset loaded 'development'." ``` -------------------------------- ### View mkdir failed error message Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/errors.md The error message format when fs.mkdir fails. ```text tabsets.wezterm: mkdir failed: {stderr_output} ``` -------------------------------- ### fs.is_file(path: string): boolean Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Checks whether a path exists and is a regular file. ```APIDOC ## fs.is_file(path: string): boolean ### Description Checks whether a path is a regular file. Returns true only if the path exists and refers to a regular file (not a directory, symlink, or special file). ### Parameters - **path** (string) - Required - Filesystem path to check ### Return Type boolean ``` -------------------------------- ### Resolve executable path Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/internal-helpers.md Resolves an executable name to an absolute path using fs.is_executable or the system PATH. ```lua local function resolve_executable(path: string): string | nil ``` ```lua if fs.is_executable(path) then return path end local shell_path = fs.which(fs.basename(path)) if shell_path then return shell_path end log_error("Failed to resolve executable '" .. path .. "'.") return nil ``` ```lua local vim_path = resolve_executable("vim") -- If vim is in PATH: Returns "/usr/bin/vim" -- If vim is not found: Returns nil, logs error local abs_path = resolve_executable("/usr/local/bin/myapp") -- If /usr/local/bin/myapp is executable: Returns "/usr/local/bin/myapp" -- Otherwise: Falls back to which("myapp"), or nil ``` -------------------------------- ### Checking executable permissions with fs.is_executable Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Determines if a path exists and has execute permissions for the current user using POSIX test -x. ```lua local fs = require "tabsets.fs" if fs.is_executable("/bin/bash") then print("Bash shell is available") end ``` ```lua if fs.is_executable(executable_path) then -- Spawn process else log_error("Executable not found or not executable") end ``` -------------------------------- ### Define TabsetOptions structure Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/types.md Lua class definition for the TabsetOptions configuration object. ```lua ---@class TabsetOptions ---@field tabsets_dir? string ---@field restore_colors? boolean ---@field restore_dimensions? boolean ---@field fuzzy_selector? boolean ``` -------------------------------- ### Serialize and save data with save_to_json_file Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/internal-helpers.md Serializes a Lua table to a JSON file. Returns true on success and false on failure. ```lua local data = { window_width = 1280, window_height = 720, tabs = { ... } } local success = save_to_json_file(data, "/home/user/.config/wezterm/tabsets.wezterm/dev.tabset.json") if not success then log_and_notify(window, "Failed to save tabset", { error = true }) end ``` -------------------------------- ### fs.rmdir Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Removes an empty directory using the POSIX rmdir command. ```APIDOC ## fs.rmdir(path: string) ### Description Removes an empty directory. Fails if the directory is not empty or does not exist. ### Parameters - **path** (string) - Required - Path to empty directory to remove ### Return Type - **boolean** - true on success, false on failure ### Example ```lua local fs = require "tabsets.fs" if fs.rmdir("/home/user/empty_dir") then print("Empty directory removed") end ``` ``` -------------------------------- ### Check target path before renaming Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/errors.md Verify that the destination path is available to avoid overwriting existing files during a rename operation. ```lua -- Check target does not exist before renaming if fs.is_path(new_file) then log_and_notify(window, "Target already exists", { error = true }) return end ``` -------------------------------- ### recreate_tabset Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/types.md Applies a TabsetData object to a window to recreate the saved layout. ```APIDOC ## recreate_tabset(window: wezterm.window, tabset_data: TabsetData) ### Description Accepts a TabsetData structure and applies it to the specified window to recreate the saved tab and pane configuration. ### Parameters - **window** (wezterm.window) - The target window. - **tabset_data** (TabsetData) - The data structure containing the layout to recreate. ### Returns - **boolean** - Returns true if the tabset was successfully recreated. ``` -------------------------------- ### fs.is_directory(path: string): boolean Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Checks whether a path exists and is a directory. ```APIDOC ## fs.is_directory(path: string): boolean ### Description Checks whether a path exists and is a directory. Returns true only if the path exists and refers to a directory. ### Parameters - **path** (string) - Required - Filesystem path to check ### Return Type boolean ``` -------------------------------- ### Debug logging commands Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/errors.md Commands to monitor WezTerm logs for tabsets-related errors. ```bash # Run WezTerm with debug logging wezterm --config-file ~/.config/wezterm/wezterm.lua 2>&1 | grep tabsets.wezterm # Or check the WezTerm debug log file tail -f ~/.local/share/wezterm/log/wezterm.log | grep tabsets.wezterm ``` -------------------------------- ### Move or rename files with fs.mv Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Renames or moves files and directories across filesystems using the POSIX mv command. ```lua local fs = require "tabsets.fs" if fs.mv("/home/user/.config/wezterm/tabsets.wezterm/old.tabset.json", "/home/user/.config/wezterm/tabsets.wezterm/new.tabset.json") then print("Tabset renamed") end ``` ```lua local old_file = tabset_file(old_name) local new_file = tabset_file(new_name) if fs.mv(old_file, new_file) then log_and_notify(window, "Tabset renamed to '" .. new_name .. "'.") else log_and_notify(window, "Unable to rename tabset", { error = true }) end ``` -------------------------------- ### load_from_json_file Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/types.md Loads tabset data from a JSON file. ```APIDOC ## load_from_json_file(file_path: string) ### Description Reads and parses a JSON file to return a TabsetData object. ### Parameters - **file_path** (string) - The path to the .tabset.json file. ### Returns - **TabsetData | nil** - The loaded tabset data or nil if loading failed. ``` -------------------------------- ### save_tabset Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Interactively saves the current window layout as a named tabset. ```APIDOC ## save_tabset(window) ### Description Captures the current window's tab layout, pane arrangement, dimensions, colors, and working directories. Prompts the user for a name and saves the data to a JSON file. ### Signature `function M.save_tabset(window: wezterm.window): nil` ### Parameters - **window** (wezterm.window) - Required - The active WezTerm window. ``` -------------------------------- ### load_tabset_by_name Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Loads and restores a tabset by its logical name without displaying a selector. ```APIDOC ## function load_tabset_by_name(window, tabset_name) ### Description Loads a specific tabset by name and recreates the tab layout. Internally constructs the file path as {tabsets_dir}/{tabset_name}.tabset.json. ### Parameters - **window** (wezterm.window) - Required - The active WezTerm window - **tabset_name** (string) - Required - Logical tabset name (without extension) ### Errors - Notification: Tabset file not found - Notification: Failed to parse JSON data - Notification: Failed to recreate tabs/panes ``` -------------------------------- ### Recreate tabset function signature Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/internal-helpers.md Defines the interface for the primary function used to restore window layouts from tabset data. ```lua local function recreate_tabset(window: wezterm.window, tabset_data: TabsetData): boolean ``` -------------------------------- ### Verify file deletion Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/errors.md Check the result of the deletion operation to handle potential file locks or permission issues. ```lua -- Verify file can be deleted before attempting if not fs.rm(file_path) then log_error("Could not delete: " .. file_path) return false end ``` -------------------------------- ### Handle rm failure in Lua Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/errors.md Check the return value of fs.rm to handle deletion failures gracefully. ```lua if not fs.rm(file_path) then log_error("Could not delete file") return false end ``` -------------------------------- ### Define TabsetTabData structure Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/types.md Lua class definition for TabsetTabData. ```lua ---@class TabsetTabData ---@field title string ---@field panes TabsetPaneData[] ``` -------------------------------- ### fs.rm Source: https://github.com/srackham/tabsets.wezterm/blob/main/_autodocs/api-reference.md Removes a file using the POSIX rm -f command. ```APIDOC ## fs.rm(path: string) ### Description Removes a file at the specified path. Does not fail if the file does not exist. ### Parameters - **path** (string) - Required - Path to file to remove ### Return Type - **boolean** - true on success, false on failure ### Example ```lua local fs = require "tabsets.fs" if fs.rm("/home/user/.config/wezterm/tabsets.wezterm/old.tabset.json") then print("Tabset deleted successfully") end ``` ```