### Example Full Configuration Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/configuration.md An example TOML configuration file demonstrating various settings including caching, session blacklisting, default session commands, and custom session setups. ```toml # Enable caching cache = true # Number of directory levels in auto-generated names dir_length = 2 # Session blacklist blacklist = ["scratch", "temp"] # Order sessions are listed sort_order = ["config", "tmux", "zoxide"] # Default settings for all sessions [default_session] startup_command = "clear" windows = ["main"] # Custom session setup [[session]] name = "myapi" path = "~/code/myapi" startup_command = "npm run dev" preview_command = "git log --oneline -3" ``` -------------------------------- ### NewConfiguratorWithPath Example Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/configurator.md Example demonstrating how to use NewConfiguratorWithPath to create a Configurator with a custom configuration file path. ```go configurator := configurator.NewConfiguratorWithPath( osImpl, pathImpl, runtimeImpl, "/custom/path/sesh.toml", ) config, err := configurator.GetConfig() ``` -------------------------------- ### NewConnector Example Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/connector.md Example demonstrating the creation of a new Connector instance and its subsequent use to connect to a session. ```go connector := connector.NewConnector( config, dir, home, lister, namer, startup, tmux, zoxide, tmuxinator, ) session, err := connector.Connect("myproject", model.ConnectOpts{ Switch: true, }) ``` -------------------------------- ### Load and Parse Configuration Example Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/configurator.md Example demonstrating how to create a Configurator and retrieve the parsed configuration. It includes error handling for ConfigError and other potential errors. ```go configurator := configurator.NewConfigurator(os, path, runtime) config, err := configurator.GetConfig() if err != nil { var configErr *configurator.ConfigError if errors.As(err, &configErr) { fmt.Println("Config Error:", configErr.Error()) fmt.Println("Details:", configErr.Human()) } return err } ``` -------------------------------- ### NewNamer Constructor Example Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/namer.md Example of creating a new Namer instance with its required dependencies. ```go namer := namer.NewNamer(pathwrap, git, home, config) // Generate names name, err := namer.Name("/home/user/projects/myapp") rootName, err := namer.RootName("/home/user/projects/myapp/src/utils") ``` -------------------------------- ### NewConfigurator Example Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/configurator.md Example demonstrating the usage of the NewConfigurator constructor to create a Configurator instance and fetch configuration. ```go configurator := configurator.NewConfigurator(osImpl, pathImpl, runtimeImpl) config, err := configurator.GetConfig() ``` -------------------------------- ### Install Sesh via Go Source: https://github.com/joshmedeski/sesh/blob/main/README.md Install the latest version of Sesh using Go's go install command. Ensure your Go environment is set up. ```go go install github.com/joshmedeski/sesh/v2@latest ``` -------------------------------- ### Example Usage of BuildAll Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/dependency-injection.md Shows how to use the BuildAll method to construct the full dependency graph and then use the Lister to retrieve sessions, demonstrating integration with other components. ```go base := seshcli.NewBaseDeps() deps, err := base.BuildAll("") // Use default config path if err != nil { return err } sessions, err := deps.Lister.List(lister.ListOptions{ Tmux: true, Zoxide: true, }) ``` -------------------------------- ### Merged Configuration Example Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/configurator.md Example illustrating how configuration files can import each other, leading to a merged configuration. Later imports override earlier ones. ```toml # ~/.config/sesh/sesh.toml import = ["~/.sesh-work.toml"] [default_session] startup_command = "clear" # ~/.sesh-work.toml [[session]] name = "api" path = "~/work/api" startup_command = "npm start" ``` -------------------------------- ### TOML Import Paths Example Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/configurator.md Example of TOML syntax for importing other configuration files. Supports tilde expansion and environment variable expansion. ```toml import = [ "~/.sesh-common.toml", "$XDG_CONFIG_HOME/sesh/work.toml" ] ``` -------------------------------- ### Logging Environment Variable Setup Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/README.md Provides examples of setting the ENV environment variable to control the logging level for Sesh. Supported levels are debug, info, and error. ```bash export ENV=debug # Debug level export ENV=info # Info level export ENV=error # Error level # (default: warn, file-only) ``` -------------------------------- ### TOML Configuration Example Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/README.md Provides an example of the TOML configuration file format for Sesh, including global settings and default session configurations. ```toml # Global settings cache = true dir_length = 2 mux_command = "tmux" sort_order = ["config", "tmux", "zoxide"] # Default session config [default_session] startup_command = "clear" windows = ["main"] ``` -------------------------------- ### Define Session with Startup and Preview Commands Source: https://github.com/joshmedeski/sesh/blob/main/README.md Configure individual sessions with specific startup commands for environment setup and preview commands for displaying file contents. The `startup_command` is skipped if the `--command/-c` flag is used. ```toml [[session]] name = "Downloads 📥" path = "~/Downloads" startup_command = "ls" [[session]] name = "tmux config" path = "~/c/dotfiles/.config/tmux" startup_command = "nvim tmux.conf" preview_command = "bat --color=always ~/c/dotfiles/.config/tmux/tmux.conf" ``` -------------------------------- ### NewPicker Constructor Example Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/picker.md Demonstrates creating a new Picker instance with configuration and using it to select a session. It logs fatal errors and prints the selected session. ```go picker := picker.NewPicker(config) // Use in command chosen, err := picker.Pick(func() (model.SeshSessions, error) { return lister.List(opts) }, picker.PickerOptions{}) ``` ```go if err != nil { log.Fatal(err) } fmt.Println("Selected:", chosen) ``` -------------------------------- ### Name Method Example Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/namer.md Demonstrates using the Name method with different scenarios, including Git repositories, directory structures, and symlinks. ```go namer := namer.NewNamer(pathwrap, git, home, config) // From git repo: uses origin/main branch name or repo name name, err := namer.Name("/home/user/projects/myapp") // Returns: "myapp" // From directory: uses last dir component(s) name, err = namer.Name("/home/user/code/api/src") // With dir_length=1: "src" // With dir_length=2: "api-src" // With symlinks: resolves first name, err = namer.Name("/tmp/mylink") // If mylink -> /home/user/projects/app // Returns: "app" ``` -------------------------------- ### ConfigError Handling Example Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/configurator.md Example demonstrating how to catch and handle ConfigError, specifically extracting human-readable details using the Human() method. ```go config, err := configurator.GetConfig() if err != nil { var configErr *configurator.ConfigError if errors.As(err, &configErr) { // Show detailed error fmt.Println(configErr.Human()) } else { // Handle other errors (file not found, etc) fmt.Println(err) } } ``` -------------------------------- ### Install Sesh via Homebrew Source: https://github.com/joshmedeski/sesh/blob/main/README.md Install the Sesh CLI using the Homebrew package manager. ```sh brew install sesh ``` -------------------------------- ### Tmuxinator Usage Example Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/external-integrations.md Demonstrates how to use the Tmuxinator interface to list configurations and retrieve a specific config's content. ```go tmuxinator := tmuxinator.NewTmuxinator(shellImpl) configs, err := tmuxinator.ListConfigs() for _, config := range configs { fmt.Println(config.Name) } // Get and apply config content, err := tmuxinator.GetConfig("myproject") ``` -------------------------------- ### Verify Setup with Tests Source: https://github.com/joshmedeski/sesh/blob/main/CONTRIBUTING.md Run the test suite to ensure your development environment is set up correctly. This command uses the 'just' build tool. ```sh just test ``` -------------------------------- ### Go Testing with Mocks Example Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/README.md Illustrates how to test Sesh components using mock implementations of its interfaces. This example shows injecting a mock Lister into the Connector. ```go func TestMyFunction(t *testing.T) { mockLister := &mocks.MockLister{} mockLister.On("List", mock.Anything).Return( model.SeshSessions{ /* ... */ }, nil, ) connector := connector.NewConnector( config, dir, home, mockLister, // inject mock namer, startup, tmux, zoxide, tmuxinator, ) // Test with mock _, err := connector.Connect("test", model.ConnectOpts{}) assert.NoError(t, err) } ``` -------------------------------- ### Install Sesh via Pixi Source: https://github.com/joshmedeski/sesh/blob/main/README.md Install Sesh globally using the Pixi package manager. ```sh pixi global install sesh ``` -------------------------------- ### Go Library Usage Example Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/README.md Demonstrates how to use the Sesh library in Go to list sessions and connect to a specific session. It shows the creation of base dependencies and building full dependencies from configuration. ```go package main import ( "github.com/joshmedeski/sesh/v2/seshcli" "github.com/joshmedeski/sesh/v2/model" ) func main() { // Create base dependencies base := seshcli.NewBaseDeps() // Build full dependencies from config deps, err := base.BuildAll("") // "" = use default config path if err != nil { panic(err) } // List sessions sessions, err := deps.Lister.List(lister.ListOptions{ Tmux: true, Zoxide: true, }) if err != nil { panic(err) } // Connect to a session err = deps.Connector.Connect("myproject", model.ConnectOpts{ Switch: true, }) } ``` -------------------------------- ### Basic Picker Usage Example Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/picker.md Demonstrates how to use the Picker to select a session with default options. It fetches sessions using a lister and connects to the chosen session. ```go picker := picker.NewPicker(config) // Simple picker with default options chosen, err := picker.Pick(func() (model.SeshSessions, error) { return lister.List(lister.ListOptions{ Tmux: true, Zoxide: true, }) }, picker.PickerOptions{}) ``` ```go if err != nil { return err } if chosen == "" { return nil // User quit } // Connect to chosen session connector.Connect(chosen, model.ConnectOpts{}) ``` -------------------------------- ### Generate and Install Zsh Completion Source: https://github.com/joshmedeski/sesh/blob/main/README.md Generates the Zsh completion script and installs it system-wide or for user-only. ```sh # Generate completion script sesh completion zsh > _sesh # Install system-wide (recommended) sudo mkdir -p /usr/local/share/zsh/site-functions sudo cp _sesh /usr/local/share/zsh/site-functions/ # Or install user-only mkdir -p ~/.zsh/completions cp _sesh ~/.zsh/completions/ echo 'fpath=(~/.zsh/completions $fpath)' >> ~/.zshrc echo 'autoload -U compinit && compinit' >> ~/.zshrc # Reload your shell source ~/.zshrc ``` -------------------------------- ### Generate and Install Fish Completion Source: https://github.com/joshmedeski/sesh/blob/main/README.md Generates the Fish completion script and installs it to the Fish configuration directory. ```sh # Generate and install completion sesh completion fish > ~/.config/fish/completions/sesh.fish # Reload fish configuration source ~/.config/fish/config.fish ``` -------------------------------- ### Install Sesh via AUR (yay) Source: https://github.com/joshmedeski/sesh/blob/main/README.md Install the Sesh CLI from the Arch User Repository using yay. ```sh yay -S sesh-bin ``` -------------------------------- ### Create New Lister Instance Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/lister.md Initializes a new Lister with necessary dependencies for session discovery. The example shows creating the Lister and then listing sessions. ```go lister := lister.NewLister(config, home, tmux, zoxide, tmuxinator) sessions, err := lister.List(lister.ListOptions{ Tmux: true, Zoxide: true, }) ``` -------------------------------- ### Connector Usage Examples Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/connector.md Demonstrates how to use the Connect method to connect to an existing session, create a new session with a command, or use tmuxinator for session creation. ```go connector := connector.NewConnector(config, dir, home, lister, namer, startup, tmux, zoxide, tmuxinator) // Connect to existing session err := connector.Connect("myproject", ConnectOpts{}) // Create new session and run command err := connector.Connect("~/code/api", ConnectOpts{ Command: "npm start", Switch: true, }) // Use tmuxinator for creation err := connector.Connect("myconfig", ConnectOpts{ Tmuxinator: true, }) ``` -------------------------------- ### Git Naming Strategy Examples Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/namer.md Shows how repository names are extracted from Git remote URLs or fall back to directory names. ```go // Examples: // - URL: `git@github.com:user/myapp.git` → "myapp" // - URL: `https://github.com/user/api-server` → "api-server" // - URL: `../sibling/repo.git` → "repo" // - No remote → Falls back to directory name ``` -------------------------------- ### Example Usage of BaseDeps Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/dependency-injection.md Demonstrates immediate use of BaseDeps for operations that do not require configuration, such as accessing the home directory or finding the Git root. ```go base := seshcli.NewBaseDeps() // Can use immediately for operations that don't need config homeDir, _ := base.Home.Home() gitRoot, _ := base.Dir.RootDir("/some/path") ``` -------------------------------- ### Example Test with Mocked Dependencies Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/dependency-injection.md Demonstrates how to create and use mocks for dependencies in a Go test. Expectations are set on mocks before creating the service instance. ```go func TestConnector(t *testing.T) { // Create mocks mockLister := &mocks.MockLister{} mockTmux := &mocks.MockTmux{} // Set expectations mockLister.On("FindTmuxSession", "myapp").Return( model.SeshSession{Name: "myapp"}, true, ) // Create connector with mocks connector := connector.NewConnector( config, mockDir, home, mockLister, namer, startup, mockTmux, zoxide, tmuxinator, ) // Test _, err := connector.Connect("myapp", model.ConnectOpts{}) assert.NoError(t, err) // Verify calls mockLister.AssertExpectations(t) mockTmux.AssertExpectations(t) } ``` -------------------------------- ### Install Taplo for Neovim Source: https://github.com/joshmedeski/sesh/blob/main/README.md Installs the taplo CLI tool using Homebrew, which is required for JSON Schema integration with Neovim. ```shell brew install taplo ``` -------------------------------- ### Install Sesh via Conda/Mamba Source: https://github.com/joshmedeski/sesh/blob/main/README.md Install Sesh using Conda or Mamba from the conda-forge channel. ```sh conda -c conda-forge install sesh ``` -------------------------------- ### Startup Interface Definition Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/session-management.md Defines the contract for executing session startup commands, including window creation and script execution. Essential for automating the initial setup of a session environment. ```go type Startup interface { Exec(session SeshSession) (string, error) } ``` -------------------------------- ### Replace Method Example Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/session-management.md Demonstrates how to use the Replace method to substitute variables in a command string. Variables can be in `${VAR_NAME}` or `$VAR_NAME` format. ```go replacer := replacer.NewReplacer() cmd := "cd ${SESSION_PATH} && npm start" replacements := map[string]string{ "SESSION_PATH": "/home/user/projects/myapp", } result := replacer.Replace(cmd, replacements) // Returns: "cd /home/user/projects/myapp && npm start" ``` -------------------------------- ### Tmux Constructor and Usage Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/external-integrations.md Constructs a Tmux interface using OS and shell abstractions. Examples show creating a Tmux instance and listing/creating sessions. ```go func NewTmux(os Os, shell Shell, bin string) Tmux ``` ```go tmux := tmux.NewTmux(osImpl, shellImpl, "tmux") // or custom binary tmux := tmux.NewTmux(osImpl, shellImpl, "/usr/local/bin/tmux") sessions, err := tmux.ListSessions() newSession, err := tmux.NewSession("myapp", "/home/user/projects/myapp") ``` -------------------------------- ### Zoxide Constructor and Usage Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/external-integrations.md Constructs a Zoxide interface using a shell implementation. Examples demonstrate listing results, formatting output, and adding new paths. ```go func NewZoxide(shell Shell) Zoxide ``` ```go zoxide := zoxide.NewZoxide(shellImpl) results, err := zoxide.ListResults() for _, r := range results { fmt.Printf("%s (score: %.2f)\n", r.Path, r.Score) } // Add path after creating session zoxide.Add("/home/user/projects/newproject") ``` -------------------------------- ### Standard Go Error Handling Example Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/README.md Shows how to handle standard Go errors using logging for context. It logs the error details and returns a wrapped error for better traceability. ```go sessions, err := lister.List(opts) if err != nil { slog.Error("list sessions failed", "error", err) return fmt.Errorf("couldn't list sessions: %w", err) } ``` -------------------------------- ### Icon Interface Usage Example Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/session-management.md Shows how to use the AddIcon, AddIconNoColor, and RemoveIcon methods to manage session icons. AddIcon applies color based on session source, while AddIconNoColor does not. ```go icon := icon.NewIcon(config) session := model.SeshSession{ Name: "myapp", Src: "tmux", } styled := icon.AddIcon(session) // Returns: "🗐 myapp" (with blue color) plain := icon.AddIconNoColor(session) // Returns: "🗐 myapp" (no color) name := icon.RemoveIcon("🗐 myapp") // Returns: "myapp" ``` -------------------------------- ### Git Constructor and Usage Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/external-integrations.md Constructs a Git interface using a shell implementation. Examples show checking for a repository root and cloning a repository. ```go func NewGit(shell Shell) Git ``` ```go git := git.NewGit(shellImpl) found, root, err := git.ShowTopLevel("/home/user/projects/myapp") if found { fmt.Println("Repo root:", root) } // Clone repository git.Clone("https://github.com/user/repo.git", "/home/user", "myrepo") ``` -------------------------------- ### TOML Configuration with Environment Variables Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/configurator.md Example of a Sesh TOML configuration file demonstrating the use of environment variables for importing other configuration files and defining wildcard patterns. Supports tilde expansion and environment variable expansion. ```toml import = ["$HOME/.sesh-private.toml"] [[wildcard]] pattern = "$PROJECTS_DIR/*" startup_command = "direnv allow" ``` -------------------------------- ### List Sessions with Options Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/lister.md Lists sessions from configured sources with options for filtering and deduplication. Use this to get a comprehensive list of available sessions based on your needs. ```go sessions, err := lister.List(lister.ListOptions{ Config: true, Tmux: true, Zoxide: true, HideAttached: false, HideDuplicates: true, }) if err != nil { return err } // Iterate in order for _, name := range sessions.OrderedIndex { session := sessions.Directory[name] fmt.Printf("%s: %s\n", session.Src, session.Name) } ``` -------------------------------- ### Generate Mocks with Mockery Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/dependency-injection.md Use mockery to automatically generate mock implementations for interfaces. Ensure mockery is installed globally. ```bash go install github.com/vektra/mockery/v2@latest mockery --all ``` -------------------------------- ### Wildcard Session Configuration Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/configuration.md Applies configuration to sessions matching glob patterns, useful for common setups in project directories. ```toml [[wildcard]] pattern = "~/work/*" startup_command = "echo 'Work project'" preview_command = "pwd && git log --oneline -5" windows = ["edit", "build", "test"] ``` -------------------------------- ### Window Definition Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/configuration.md Define a specific window within a Sesh configuration. Includes the window name and the script to run when the window starts. ```TOML [[window]] name = "editor" startup_script = "vim" ``` ```TOML [[window]] name = "terminal" startup_script = "clear" ``` -------------------------------- ### RootName Method Example Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/namer.md Demonstrates using the RootName method to find the top-level session name from a subdirectory within a Git repository or worktree. ```go // When in /home/user/projects/myapp/src name, err := namer.RootName("/home/user/projects/myapp/src") // Returns: "myapp" (the repo root name) // For git worktree at /repo/.bare/worktree-name/subdir name, err = namer.RootName("/repo/.bare/worktree-name/subdir") // Returns: "worktree-name" ``` -------------------------------- ### ConfigError Handling Example Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/README.md Demonstrates how to handle Sesh's custom ConfigError type to provide user-friendly error messages. It uses errors.As to check for the specific error type. ```go config, err := configurator.GetConfig() if err != nil { var configErr *configurator.ConfigError if errors.As(err, &configErr) { fmt.Println(configErr.Human()) // User-friendly message } } ``` -------------------------------- ### Path Substitution in Default Session Commands Source: https://github.com/joshmedeski/sesh/blob/main/README.md Utilize the `{}` placeholder in default session commands to dynamically insert the session's path. This is demonstrated with a `tmuxinator` example. ```toml [default_session] startup_command = "tmuxinator start default_project path={}" preview_command = "eza --all --git --icons --color=always {}" ``` -------------------------------- ### NewStartup Constructor Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/session-management.md Creates a new instance of the Startup interface. Requires various dependencies for configuration, session listing, tmux interaction, path handling, and command replacement. ```go func NewStartup( config Config, lister Lister, tmux Tmux, home Home, replacer Replacer, ) Startup ``` -------------------------------- ### Startup.Exec Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/session-management.md Executes session startup commands, creates windows, and runs startup scripts for a given session. ```APIDOC ## Exec ### Description Execute startup commands for a session. Creates windows and runs startup scripts. ### Method Exec ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **session** (SeshSession) - Required - Session to start (contains name, path, startup config) ### Request Example ```go startup.Exec(model.SeshSession{ Name: "myapp", Path: "/home/user/projects/myapp", StartupCommand: "npm start", WindowNames: []string{"main", "test"}, }) ``` ### Response #### Success Response (200) - **string** - Command output (currently implementation returns "") - **error** - nil if successful #### Response Example ``` "" ``` ### Errors - Error if execution failed ``` -------------------------------- ### Configure Default Session Startup and Preview Commands Source: https://github.com/joshmedeski/sesh/blob/main/README.md Set a default startup command to run when connecting to a session and a preview command for displaying session directory contents. The `{}` placeholder is automatically replaced with the session's path. ```toml [default_session] startup_command = "nvim -c ':Telescope find_files'" preview_command = "eza --all --git --icons --color=always {}" ``` -------------------------------- ### Execute Session Startup Commands Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/session-management.md Executes startup commands for a given session, creating necessary windows and running configured startup scripts. Supports multiple startup strategies based on session configuration. ```go startup := startup.NewStartup(config, lister, tmux, home, replacer) session := model.SeshSession{ Name: "myapp", Path: "/home/user/projects/myapp", StartupCommand: "npm start", WindowNames: []string{"main", "test"}, } err := startup.Exec(session) // Creates windows "main" and "test" // Runs startup command in main window ``` -------------------------------- ### GetLastTmuxSession Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/lister.md Get the most recently attached tmux session. ```APIDOC ## GetLastTmuxSession ### Description Get the most recently attached tmux session. ### Method GetLastTmuxSession ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go last, exists := lister.GetLastTmuxSession() if exists { fmt.Printf("Last: %s\n", last.Name) } ``` ### Response #### Success Response (200) - **SeshSession** - Last session - **bool** - True if found, false if no sessions exist #### Response Example None provided in source. ``` -------------------------------- ### GetAttachedTmuxSession Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/lister.md Get the currently attached tmux session (when running inside tmux). ```APIDOC ## GetAttachedTmuxSession ### Description Get the currently attached tmux session (when running inside tmux). ### Method GetAttachedTmuxSession ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go session, inside := lister.GetAttachedTmuxSession() if inside { fmt.Printf("Current: %s\n", session.Name) } else { fmt.Println("Not in tmux") } ``` ### Response #### Success Response (200) - **SeshSession** - Current session - **bool** - True if inside tmux, false otherwise #### Response Example None provided in source. ``` -------------------------------- ### Generate and Install PowerShell Completion Source: https://github.com/joshmedeski/sesh/blob/main/README.md Generates the PowerShell completion script and adds it to the PowerShell profile. ```powershell # Generate completion script sesh completion powershell > sesh.ps1 # Create PowerShell profile directory if it doesn't exist mkdir -p (Split-Path $PROFILE) # Add to PowerShell profile Add-Content $PROFILE ". /path/to/sesh.ps1" # Reload PowerShell & $PROFILE ``` -------------------------------- ### Create Default Configuration File Source: https://github.com/joshmedeski/sesh/blob/main/README.md Creates the necessary directory and an empty sesh.toml file in the default configuration path. ```shell mkdir -p ~/.config/sesh && touch ~/.config/sesh/sesh.toml ``` -------------------------------- ### Picker Usage with Custom Options Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/picker.md Shows how to use the Picker with custom prompt, placeholder, and icon display enabled. It fetches sessions using a provided fetchFunc. ```go // With custom options prompt := "Select: " placeholder := "Type to search..." showIcons := true chosen, err := picker.Pick(fetchFunc, picker.PickerOptions{ Prompt: &prompt, Placeholder: &placeholder, ShowIcons: &showIcons, }) ``` -------------------------------- ### Dependency Injection - Full Dependencies Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/README.md Lists the full set of dependencies for Sesh, created after configuration is loaded. ```go BaseDeps + Config, Tmux, Lister, Picker, CachingLister, Startup, Namer, Connector, Icon, Previewer, Cloner ``` -------------------------------- ### Cloner.Clone Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/session-management.md Clones a Git repository and creates a new session in the cloned directory. It handles Git operations and session connection setup. ```APIDOC ## Clone ### Description Clone a git repository and create a session in the cloned directory. ### Method Clone ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **opts.Repo** (string) - Required - Git repository URL to clone - **opts.CmdDir** (string) - Optional - Directory to run clone command in (default: current) - **opts.Dir** (string) - Optional - Target directory name (default: derived from repo URL) ### Request Example ```go cloner.Clone(model.GitCloneOptions{ Repo: "https://github.com/user/myrepo.git", CmdDir: "/home/user/projects", Dir: "myproject", }) ``` ### Response #### Success Response (200) - **string** - Path to the cloned directory - **error** - nil if successful #### Response Example ``` "/home/user/projects/myproject" ``` ### Errors - Git clone errors (authentication, not a repo, etc.) - Connection errors - Invalid directory ``` -------------------------------- ### Configuration Error Handling Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/dependency-injection.md Demonstrates how to handle specific configuration errors using `errors.As` to check for a custom `ConfigError` type and extract user-friendly messages. ```go config, err := configurator.GetConfig() if err != nil { var configErr *configurator.ConfigError if errors.As(err, &configErr) { fmt.Println(configErr.Human()) // User-friendly error } return err } ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/joshmedeski/sesh/blob/main/CONTRIBUTING.md Clone your forked repository and navigate into the project directory. Replace YOUR_USERNAME with your GitHub username. ```sh git clone https://github.com/YOUR_USERNAME/sesh.git cd sesh ``` -------------------------------- ### Get Last Tmux Session Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/lister.md Retrieves the most recently attached tmux session. Returns the session details and a boolean indicating if a last session was found. ```go last, exists := lister.GetLastTmuxSession() if exists { fmt.Printf("Last: %s\n", last.Name) } ``` -------------------------------- ### Define Session with Multiple Windows Source: https://github.com/joshmedeski/sesh/blob/main/README.md Configure sessions to include multiple windows, specifying startup scripts for each window. If a window path is not specified, it defaults to the session's path. ```toml [[session]] name = "Downloads 📥" path = "~/Downloads" startup_command = "ls" [[session]] name = "tmux config" path = "~/c/dotfiles/.config/tmux" startup_command = "nvim tmux.conf" preview_command = "bat --color=always ~/c/dotfiles/.config/tmux/tmux.conf" windows = [ "git" ] [[window]] name = "git" startup_script = "git pull" ``` -------------------------------- ### NewPreviewer Constructor Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/session-management.md Creates a new instance of the Previewer interface. Requires multiple dependencies for session listing, tmux interaction, icon handling, directory operations, path expansion, and command execution. ```go func NewPreviewer( lister Lister, tmux Tmux, icon Icon, dir Dir, home Home, ls Ls, config Config, shell Shell, ) Previewer ``` -------------------------------- ### Real Implementation Structure Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/dependency-injection.md Illustrates the standard pattern for real package implementations in Go, emphasizing private fields and a constructor function that accepts interfaces. ```go type RealPackage struct { // Private fields with lowercase names dep1 Interface1 dep2 Interface2 } // Constructor func New(dep1 Interface1, dep2 Interface2) Interface { return &RealPackage{dep1, dep2} } // Methods implement Interface func (r *RealPackage) Method() error { // Implementation } ``` -------------------------------- ### Build Sesh Project Source: https://github.com/joshmedeski/sesh/blob/main/CLAUDE.md Use 'just build' to compile the Sesh project. Specify a version to build a specific release. ```bash just build # Build to $GOPATH/bin/sesh just build v2.0.0 # Build with specific version ``` -------------------------------- ### Get Attached Tmux Session Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/lister.md Retrieves the currently attached tmux session. Returns the session details and a boolean indicating if the command is being run inside tmux. ```go session, inside := lister.GetAttachedTmuxSession() if inside { fmt.Printf("Current: %s\n", session.Name) } else { fmt.Println("Not in tmux") } ``` -------------------------------- ### Dependency Injection - Base Dependencies Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/README.md Lists the base dependencies for Sesh that do not require configuration, created eagerly. ```go Exec, Os, Path, Runtime, Home, Shell, Json, Replacer, Git, Dir, Zoxide, Tmuxinator ``` -------------------------------- ### Home Interface Definition Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/external-integrations.md Defines the interface for home directory operations. Provides methods to get the user's home directory path and expand paths relative to it. ```go type Home interface { Home() string ExpandPath(path string) (string, error) } ``` -------------------------------- ### Import Paths with Environment Variables Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/configuration.md Specify configuration files to import using environment variables and path expansion. Supports user home directory expansion (`~`) and environment variable expansion (`$VAR_NAME`). ```TOML import = ["$XDG_CONFIG_HOME/sesh/common.toml", "~/.sesh-private.toml"] ``` -------------------------------- ### Wildcard Project Configuration Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/configuration.md Define a wildcard pattern to match multiple work projects. Specifies startup commands and default windows for matched projects. ```TOML [[wildcard]] pattern = "~/work/*" startup_command = "direnv allow" windows = ["editor", "terminal"] ``` -------------------------------- ### Specify Custom Configuration Path Source: https://github.com/joshmedeski/sesh/blob/main/README.md Demonstrates how to use the --config flag to specify a custom sesh.toml file. This is useful for managing multiple configurations or for use in environments like NixOS. ```shell sesh -C /path/to/custom/sesh.toml list ``` ```shell sesh --config /path/to/custom/sesh.toml connect my-session ``` -------------------------------- ### CLI Command Structure with Dependency Injection Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/dependency-injection.md Shows how to structure a Cobra CLI command in Go, including building full dependencies from base dependencies and using injected services like a Connector. ```go func NewCommandName(base *BaseDeps) *cobra.Command { cmd := &cobra.Command{ Use: "command", RunE: func(cmd *cobra.Command, args []string) error { // Build full dependencies deps, err := buildDeps(cmd, base) if err != nil { return err } // Use deps to implement command result, err := deps.Connector.Connect(name, opts) return err }, } // Add flags cmd.Flags().StringP("flag", "f", "", "description") return cmd } ``` -------------------------------- ### Migrate Root Command Execution Source: https://github.com/joshmedeski/sesh/blob/main/docs/specs/cobra-fang-migration.md Replace urfave/cli's app.Run() with Fang's Execute() for the root command. ```go // Before (urfave) app := seshcli.App(version) app.Run(os.Args) // After (Cobra + Fang) cmd := seshcli.NewRootCommand(version) fang.Execute(context.TODO(), cmd) ``` -------------------------------- ### NewLister Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/lister.md Creates a new Lister instance with the necessary dependencies, including configuration, home directory utilities, and interfaces for tmux, zoxide, and tmuxinator. ```APIDOC ## Constructor ### NewLister ### Description Create a new Lister with required dependencies. ### Signature ```go func NewLister( config Config, home Home, tmux Tmux, zoxide Zoxide, tmuxinator Tmuxinator, ) Lister ``` ### Parameters #### Path Parameters - **config** (Config) - Required - Configuration including source order and blacklist - **home** (Home) - Required - Home directory utility - **tmux** (Tmux) - Required - Tmux interface for session discovery - **zoxide** (Zoxide) - Required - Zoxide interface for frecency results - **tmuxinator** (Tmuxinator) - Required - Tmuxinator interface for config discovery ### Returns - **Lister** - A new Lister instance. ### Example ```go lister := lister.NewLister(config, home, tmux, zoxide, tmuxinator) sessions, err := lister.List(lister.ListOptions{ Tmux: true, Zoxide: true, }) ``` ``` -------------------------------- ### Available 'just' Commands Source: https://github.com/joshmedeski/sesh/blob/main/CONTRIBUTING.md A list of common commands available through the 'just' build tool for development tasks. ```sh just mock # Generate mocks (required before testing if interfaces changed) just test # Run tests with coverage just build # Build to $GOPATH/bin/sesh ``` -------------------------------- ### Generate Preview Output for Session or Directory Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/session-management.md Retrieves preview output for a given session name or directory path. It attempts to use configured preview strategies, falling back to directory listing if necessary. ```go previewer := previewer.NewPreviewer(lister, tmux, icon, dir, home, ls, config, shell) output, err := previewer.Preview("myproject") // Returns output from configured preview command // Or "ls -la" output if no command configured output, err := previewer.Preview("/home/user/code") // Returns directory listing ``` -------------------------------- ### List Configurations Source: https://github.com/joshmedeski/sesh/blob/main/README.md Explicitly list session configurations using the -c flag. This command is useful for viewing all defined session configurations. ```sh sesh list -c ``` -------------------------------- ### Error Handling for buildDeps Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/dependency-injection.md Illustrates how to handle errors returned by the buildDeps function, specifically distinguishing between ConfigError and other general errors, and printing human-readable messages. ```go deps, err := buildDeps(cmd, base) if err != nil { var configErr *configurator.ConfigError if errors.As(err, &configErr) { fmt.Printf("Config error: %s\n", configErr.Human()) } else { fmt.Printf("Error: %v\n", err) } return err } ``` -------------------------------- ### Find Configuration by Wildcard Path Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/lister.md Finds a wildcard configuration matching a given path. Returns the matching configuration and a boolean indicating if a match was found. ```go wildcard, matched := lister.FindConfigWildcard("/home/user/work/project") if matched { fmt.Printf("Startup: %s\n", wildcard.StartupCommand) } ``` -------------------------------- ### Preview Session/Directory Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/cli-commands.md Shows preview output for a session or directory by executing a preview command and displaying its output. ```bash sesh preview sesh p ``` ```bash sesh preview myproject sesh p ~/code/api ``` -------------------------------- ### Integration Error Handling Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/dependency-injection.md Shows how to log integration errors using `slog.Error` and wrap the original error with context using `fmt.Errorf` for better debugging. ```go sessions, err := lister.List(opts) if err != nil { slog.Error("list sessions", "error", err) return fmt.Errorf("couldn't list sessions: %w", err) } ``` -------------------------------- ### BuildAll Method for Deps Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/dependency-injection.md Builds the complete dependency graph, including config-dependent components, by loading configuration from a specified path or defaults. Handles various error types gracefully. ```go func (b *BaseDeps) BuildAll(configPath string) (*Deps, error) ``` -------------------------------- ### Define ConnectOpts Struct Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/types.md Specifies options for connecting to a session, including the command to run, whether to switch to the session, and if tmuxinator should be used. ```go type ConnectOpts struct { Command string Switch bool Tmuxinator bool } ``` -------------------------------- ### Graceful Degradation for Optional Integrations Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/dependency-injection.md Illustrates handling errors from optional integrations like Zoxide by logging the error at a debug level and continuing execution without the integration's results. ```go // Zoxide is optional results, err := zoxide.ListResults() if err != nil { slog.Debug("zoxide not available", "error", err) // Continue without zoxide results } ``` -------------------------------- ### Create FileCache with Default Path Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/cache.md Creates a FileCache instance that uses the default XDG cache directory or falls back to ~/.cache/sesh/sessions.gob. This is the standard way to initialize the file cache for general use. ```go cache := cache.NewFileCache() cached, err := cache.Read() ``` -------------------------------- ### Clone Git Repository and Create Session Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/session-management.md Clones a specified Git repository and sets up a new session within the cloned directory. Ensure GitCloneOptions are correctly populated with repository URL and desired directories. ```go cloner := cloner.NewCloner(connector, git) err := cloner.Clone(model.GitCloneOptions{ Repo: "https://github.com/user/myrepo.git", CmdDir: "/home/user/projects", Dir: "myproject", }) // Creates /home/user/projects/myrepo // Connects to session in that directory ``` -------------------------------- ### Clone Repository and Connect Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/cli-commands.md Clones a git repository and immediately connects to a new session within that directory. Supports specifying the clone command directory and target directory name. ```bash sesh clone [flags] sesh cl [flags] ``` ```bash sesh clone https://github.com/user/repo.git sesh cl --cmdDir ~/src https://github.com/user/repo.git sesh cl --dir myname https://github.com/user/repo.git ``` -------------------------------- ### NewConnector Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/connector.md Creates a new instance of the Connector with all its required dependencies. ```APIDOC ## NewConnector connector.NewConnector ### Description Create a new Connector with all required dependencies. ### Method func NewConnector( config Config, dir Dir, home Home, lister Lister, namer Namer, startup Startup, tmux Tmux, zoxide Zoxide, tmuxinator Tmuxinator, ) Connector ### Parameters - `config` (Config) - Session and UI configuration - `dir` (Dir) - Directory utility for path operations - `home` (Home) - Home directory utility - `lister` (Lister) - Session discovery and lookup - `namer` (Namer) - Session naming strategy - `startup` (Startup) - Startup command execution - `tmux` (Tmux) - Tmux interface - `zoxide` (Zoxide) - Zoxide integration - `tmuxinator` (Tmuxinator) - Tmuxinator support ### Returns - Connector - A new Connector instance ready for use. ### Example ```go connector := connector.NewConnector( config, dir, home, lister, namer, startup, tmux, zoxide, tmuxinator, ) session, err := connector.Connect("myproject", model.ConnectOpts{ Switch: true, }) ``` ``` -------------------------------- ### CLI Command Structure Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/README.md Shows the basic structure for invoking Sesh CLI commands, including the optional configuration flag. ```bash sesh [--config PATH] [options] ``` -------------------------------- ### Default Session Configuration Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/configuration.md Defines default settings applied to all sessions, such as startup commands, preview commands, and window names. ```toml [default_session] startup_command = "echo 'Session started'" preview_command = "ls -la" tmuxinator = "default_config" windows = ["main", "dev"] ``` -------------------------------- ### NewConfiguratorWithPath Constructor Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/configurator.md Function signature for NewConfiguratorWithPath, which creates a Configurator instance with an explicitly specified configuration file path. ```go func NewConfiguratorWithPath( os Os, path Path, runtime Runtime, configPath string, ) Configurator ``` -------------------------------- ### Home Interface Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/external-integrations.md Provides methods for interacting with the user's home directory. ```APIDOC ## Home Interface ### Description Home directory operations. ### Methods #### Home() - **Description**: Returns the path to the user's home directory. - **Returns**: The home directory path as a string. #### ExpandPath(path string) - **Description**: Expands paths that start with `~` to the user's home directory. - **Parameters**: - **path** (string) - Required - The path to expand. - **Returns**: The expanded path as a string, or an error. ``` -------------------------------- ### Previewer.Preview Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/session-management.md Generates preview output for sessions and directories by applying a strategy based on available tools and configurations. ```APIDOC ## Preview ### Description Get preview output for a session or directory. ### Method Preview ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **name** (string) - Required - Session name or directory path ### Request Example ```go previewer.Preview("myproject") ``` ### Response #### Success Response (200) - **string** - Preview output (command result or directory listing) - **error** - nil if successful #### Response Example ``` "Output from configured preview command or directory listing" ``` ### Errors - Error if preview failed ``` -------------------------------- ### Individual Session Configuration Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/configuration.md Configures specific sessions by matching their names and overriding default settings like startup commands and paths. ```toml [[session]] name = "myproject" path = "~/projects/myproject" startup_command = "npm run dev" preview_command = "ls -la src" windows = ["main", "test"] disable_startup_command = false ``` -------------------------------- ### NewConfiguratorWithPath Constructor Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/configurator.md Creates a new Configurator instance with an explicitly specified configuration file path. ```APIDOC ### NewConfiguratorWithPath ```go func NewConfiguratorWithPath( os Os, path Path, runtime Runtime, configPath string, ) Configurator ``` **Description:** Initializes a `Configurator` pointing to a specific configuration file. Use this constructor when the configuration file is not located at the default XDG paths. **Parameters:** - `os` (`Os`): An interface for operating system functionalities, particularly file operations. - `path` (`Path`): Utilities for path manipulation. - `runtime` (`Runtime`): Utilities related to the runtime environment. - `configPath` (`string`): The explicit, absolute or relative, path to the TOML configuration file. **Returns:** A new instance of `Configurator` configured to use the provided `configPath`. **Example:** ```go configurator := configurator.NewConfiguratorWithPath( osImpl, pathImpl, runtimeImpl, "/custom/path/sesh.toml", ) config, err := configurator.GetConfig() ``` ``` -------------------------------- ### Connect to Session Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/cli-commands.md Connects to or creates a session by name. Supports connecting to paths, zoxide results, or configured sessions. Can execute a command on new session creation. ```bash sesh connect [flags] sesh cn [flags] ``` ```bash sesh connect ~/myproject sesh cn --switch ~/api # Switch instead of attach sesh cn --command "npm start" ~/web # Run command on creation sesh cn --root # Go to git root of current dir ``` -------------------------------- ### NewNamer Constructor Source: https://github.com/joshmedeski/sesh/blob/main/_autodocs/api-reference/namer.md Creates and returns a new instance of the Namer. It requires several dependencies to be provided, including path utilities, Git interface, home directory utility, and configuration settings. ```APIDOC ## NewNamer Constructor ### Description Create a new Namer with required dependencies. ### Function Signature ```go func NewNamer(pathwrap Path, git Git, home Home, config Config) Namer ``` ### Parameters - **pathwrap** (Path) - Required - Path utilities for symlink resolution - **git** (Git) - Required - Git interface for repository detection - **home** (Home) - Required - Home directory utility - **config** (Config) - Required - Configuration (dir_length setting) ### Returns - **Namer** - A new Namer instance. ### Example ```go // Assuming dependencies pathwrap, git, home, and config are initialized namer := namer.NewNamer(pathwrap, git, home, config) ``` ```