Skip to content

feat: add sesh window command for tmux window management#345

Open
fenngwd wants to merge 7 commits intojoshmedeski:mainfrom
fenngwd:feat/sesh-window-command
Open

feat: add sesh window command for tmux window management#345
fenngwd wants to merge 7 commits intojoshmedeski:mainfrom
fenngwd:feat/sesh-window-command

Conversation

@fenngwd
Copy link
Copy Markdown

@fenngwd fenngwd commented Mar 6, 2026

Summary

Closes #282

Adds a new sesh window (alias w) subcommand for listing and managing tmux windows within a session, mirroring the UX of sesh list and sesh connect.

Features

  • sesh window — list all windows in the current tmux session (one per line)
  • sesh window <name> — switch to an existing window by name
  • sesh window <path> — create a new window at the given directory (name = basename)
  • --session / -s flag to target a session other than the current one
  • --json / -j flag reserved for JSON output in list mode

Implementation

  • model/tmux_window.go — new TmuxWindow data type (Name, Path, Index, Active)
  • tmux/list_tmux_win.go + tests — ListWindows(targetSession string) using tmux list-windows
  • tmux/select_win.go + tests — SelectWindow(name string) using tmux select-window
  • seshcli/window.go — cobra command wired to the above
  • seshcli/root_command.go — registered in root command

Note: files are named list_tmux_win.go / select_win.go (not list_windows.go / select_window.go) to avoid Go's platform-specific build constraint, which treats files ending in _windows.go as Windows-only.

Testing

Unit tests follow the same mock-based pattern as the existing tmux package tests. All 14 packages pass.

Weidong Feng (AI) and others added 5 commits March 6, 2026 15:52
提交内容由AI生成

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add ListWindows(targetSession string) to the Tmux interface and RealTmux
implementation. Reuse existing separator variable from list.go to avoid
naming conflict. Note: implementation file named list_tmux_win.go because
Go treats filenames ending in _windows.go as Windows-only build constraints.

Commit content generated by AI

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Commit content generated by AI

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
提交内容由AI生成

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
提交内容由AI生成

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@joshmedeski
Copy link
Copy Markdown
Owner

Just to clarify, how would this feature be used?

Can you clarify it's purpose in the README and some basic instructions for how to use it, thanks.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new sesh window / sesh w command to list, switch to, and create tmux windows within a session, aligning window UX with existing session-oriented commands.

Changes:

  • Introduces model.TmuxWindow and tmux-layer support for listing windows and selecting a window.
  • Adds a new Cobra command sesh window and registers it in the root command.
  • Adds unit tests for the new tmux window list/select functions.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tmux/tmux.go Extends the Tmux interface with window list/select capabilities needed by the CLI.
tmux/list_tmux_win.go Implements ListWindows() using tmux list-windows parsing into TmuxWindow.
tmux/list_tmux_win_test.go Adds tests for window listing, target session flag behavior, and parsing.
tmux/select_win.go Implements SelectWindow() using tmux select-window.
tmux/select_win_test.go Adds a unit test ensuring the correct tmux command is executed.
model/tmux_window.go Adds the window model used across tmux + CLI layers.
seshcli/window.go Introduces the window subcommand wiring together list/select/create behaviors.
seshcli/root_command.go Registers the new window command at the root.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +82 to +86
newWindowArgs := []string{"new-window", "-n", windowName, "-c", absPath}
if targetSession != "" {
newWindowArgs = append(newWindowArgs, "-t", targetSession)
}
if _, err := base.Shell.Cmd("tmux", newWindowArgs...); err != nil {
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command shells out directly via base.Shell.Cmd("tmux", ...) to create a window, bypassing the tmux.Tmux abstraction. That makes the CLI harder to unit test (no tmux mock) and duplicates tmux command construction outside the tmux package. Consider adding a tmux-layer method that supports creating a window in an optional target session (e.g., extend NewWindow or add NewWindowInSession) and calling that instead.

Suggested change
newWindowArgs := []string{"new-window", "-n", windowName, "-c", absPath}
if targetSession != "" {
newWindowArgs = append(newWindowArgs, "-t", targetSession)
}
if _, err := base.Shell.Cmd("tmux", newWindowArgs...); err != nil {
if _, err := base.Tmux.NewWindowInSession(windowName, absPath, targetSession); err != nil {

Copilot uses AI. Check for mistakes.

output, err := t.shell.ListCmd("tmux", args...)
if err != nil {
return []*model.TmuxWindow{}, nil
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ListWindows swallows errors from t.shell.ListCmd and returns an empty slice with a nil error. This makes it impossible for callers to distinguish between “no windows” and a real failure (e.g., tmux not available, permission issues, malformed args). Consider returning the original err (or only suppressing the specific 'no server running' case) so CLI code can surface failures appropriately.

Suggested change
return []*model.TmuxWindow{}, nil
return nil, err

Copilot uses AI. Check for mistakes.
tmux/tmux.go Outdated
SwitchClient(targetSession string) (string, error)
CapturePane(targetSession string) (string, error)
NextWindow() (string, error)
SelectWindow(name string) (string, error)
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SelectWindow method parameter is named name, but callers can pass a full tmux target like session:window (see seshcli/window.go). Renaming the parameter to something like target/targetWindow would better reflect actual usage and reduce confusion for future callers.

Suggested change
SelectWindow(name string) (string, error)
SelectWindow(targetWindow string) (string, error)

Copilot uses AI. Check for mistakes.
Comment on lines +17 to +20
targetSession, _ := cmd.Flags().GetString("session")
jsonOutput, _ := cmd.Flags().GetBool("json")
_ = jsonOutput

Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --json/-j flag is parsed but intentionally ignored (_ = jsonOutput), so users can enable it with no observable effect. Either implement JSON output for list mode or return a clear error when --json is provided to avoid a silent no-op.

Copilot uses AI. Check for mistakes.
Weidong Feng (AI) and others added 2 commits March 12, 2026 15:35
提交内容由AI生成

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
提交内容由AI生成

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@fenngwd
Copy link
Copy Markdown
Author

fenngwd commented Mar 12, 2026

Thanks for the feedback! I've added a Window management section to the README with examples covering:

  • Listing windows in the current session
  • Switching to an existing window by name
  • Creating a new window at a directory path
  • Targeting a different session with --session
  • fzf integration example

I also addressed the 4 Copilot review suggestions in the latest commit:

  • Added NewWindowInSession to the tmux package (instead of calling Shell.Cmd directly from the CLI layer)
  • ListWindows now returns errors instead of swallowing them
  • Renamed SelectWindow parameter to targetWindow for clarity
  • Implemented --json output for list mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add commands for window management

3 participants