Sesh

repository·main·Indexed 25 days ago

https://github.com/joshmedeski/sesh

A smart tmux session manager that integrates with zoxide to allow users to quickly create, manage, and jump to tmux sessions based on git repositories or directories. It supports shell completions for Bash, Zsh, Fish, and PowerShell, and integrates with tools like fzf, Raycast, Ulauncher, and Walker.

Tokens
11.4K
Snippets
55
Records
87
Agent score
80%

What's inside Sesh

  1. Migrate Root Command from urfave to Cobra + Fang

    main

    Replace the legacy seshcli/seshcli.go logic with a new Cobra root command structure. Instead of using app.Run(), use fang.Execute() to run the command tree.

    // Before (urfave)
    app := seshcli.App(version)
    app.Run(os.Args)
    
    // After (Cobra + Fang)
    cmd := seshcli.NewRootCommand(version)
    fang.Execute(context.TODO(), cmd)
  2. Basic usage of sesh

    main

    Sesh works by leveraging zoxide for directory tracking and tmux for session management.

    • sesh list: Lists all current tmux sessions and zoxide search results.
    • sesh connect {session}: Connects to a specific session. If the session does not exist, it is automatically created.
  3. Configure shell completion for sesh

    main

    Sesh supports tab completion for Bash, Zsh, Fish, and PowerShell. Follow the specific steps for your shell to generate and install the completion scripts.

    # Bash
    sesh completion bash > sesh-completion.bash
    sudo cp sesh-completion.bash /etc/bash_completion.d/
    source ~/.bashrc
    
    # Zsh
    sesh completion zsh > _sesh
    sudo mkdir -p /usr/local/share/zsh/site-functions
    sudo cp _sesh /usr/local/share/zsh/site-functions/
    echo 'fpath=(~/.zsh/completions $fpath)' >> ~/.zshrc
    echo 'autoload -U compinit && compinit' >> ~/.zshrc
    source ~/.zshrc
    
    # Fish
    sesh completion fish > ~/.config/fish/completions/sesh.fish
    source ~/.config/fish/config.fish
    
    # PowerShell
    sesh completion powershell > sesh.ps1
    mkdir -p (Split-Path $PROFILE)
    Add-Content $PROFILE ". /path/to/sesh.ps1"
    & $PROFILE
  4. Connect to the root session of a project

    main

    When working in nested sessions, you can use the --root flag to connect to the root session of a git worktree or repository.

    Recommended tmux binding:

    bind -N "switch to root session (via sesh) " 9 run-shell "sesh connect --root $(pwd)"
  5. Use the `sesh status` command for tmux status bars

    main

    The sesh status command prints a tmux-styled string describing the GitHub issue associated with the current session's branch. It displays a state badge (green OPEN or red CLOSED) followed by the issue number and title.

    To use it in your tmux configuration (e.g., in status-left or status-right), add a line like this:

    Requirements:

    • The gh CLI must be installed and authenticated (gh auth login).
    • The issue number must be present in the branch name (e.g., 400 or feat/400-status-bar).

    If no issue is found, the branch has no number, or the gh CLI is unavailable, the command prints nothing and exits with code 0, ensuring your status bar remains clean.

    set -g status-left "#[fg=blue,bold]#S #[fg=white,nobold]#(sesh status)"
  6. Configure Zsh shell completion

    main

    To enable tab completion for Sesh in Zsh, generate the completion script and add it to your site-functions or a custom completions directory, then reload your shell.

    # 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
  7. Configure sesh using sesh.toml

    main

    You can configure sesh by creating a sesh.toml file in $XDG_CONFIG_HOME/sesh or $HOME/.config/sesh.

    To create the default configuration directory and file, run:

    mkdir -p ~/.config/sesh && touch ~/.config/sesh/sesh.toml
  8. Understand the sesh status cache behavior

    main

    The sesh status command uses a "stale-while-revalidate" pattern to ensure tmux redraws are always sub-millisecond:

    1. Instant Render: sesh status reads from a local cache keyed on the repo root + branch. It never calls gh directly.
    2. Background Refresh: If the cache entry is missing or older than the configured issue_ttl, sesh status spawns a detached background process (sesh status --refresh <path>) to fetch live data via gh and update the cache. This process does not block the tmux status line.
    3. Warm-on-Switch: When using sesh connect, a background refresh is automatically triggered for the new session's path so the cache is ready before the first redraw.
    4. Negative Caching: If a branch has no associated GitHub issue, a "negative entry" is still cached. This prevents sesh from repeatedly attempting to spawn refresh processes for branches that don't have issues.
  9. Enrich session names with GitHub issue titles

    main

    You can automatically rename tmux sessions to include the GitHub issue title associated with the current branch. This requires the gh CLI to be installed and authenticated.

    Add this hook to your tmux.conf to run the enrichment in the background whenever a new session is created:

    set-hook -g session-created 'run-shell -b "sesh rename --enrich"'
  10. Install Sesh via Conda or Pixi

    main

    Depending on your package manager, use one of the following commands:

    For Conda or (micro)mamba users:

    conda -c conda-forge install sesh

    For Pixi users:

    pixi global install sesh
    # Conda
    conda -c conda-forge install sesh
    
    # Pixi
    pixi global install sesh