Skip to content

Add New Window to the pane context menu - #23

Merged
netj merged 7 commits into
netj:mainfrom
jooddang:feat/pane-context-menu-new-window
Aug 28, 2026
Merged

Add New Window to the pane context menu#23
netj merged 7 commits into
netj:mainfrom
jooddang:feat/pane-context-menu-new-window

Conversation

@jooddang

Copy link
Copy Markdown
Contributor

Summary

  • add New Window (C-t c) to the pane right-click menu with accelerator w
  • preserve the installed tmux version default menu instead of vendoring a version-specific copy
  • create the window from the clicked pane working directory
  • fail closed on unknown menu shapes or accelerator conflicts and restore the original binding if verification fails

Design

tmux does not expose an API for appending to its built-in pane menu. The managed helper reads the canonical MouseDown3Pane binding, inserts the action only at a verified stable or floating-pane anchor, sources the candidate, and confirms the exact resulting binding. Existing and future custom menus remain untouched when the transformation cannot be proven safe.

Verification

  • uv run pytest -q — 134 passed
  • real PTY-driven tmux E2E opens the pane menu through an SGR right-click, selects w, and verifies the new window inherits the inactive clicked pane cwd
  • stable tmux 3.6a live binding preservation and reload idempotency
  • stable and current floating-pane menu shapes covered by unit tests
  • python3 -m py_compile optmux/pane_menu.py
  • uv lock --check
  • uv build; wheel and sdist contain the helper and updated tmux config
  • git diff --check origin/main

The build succeeds with the existing warning that local uv 0.12.3 is newer than the declared uv_build <0.12.0 range.

Comment thread optmux-tmux.conf Outdated
netj and others added 5 commits August 22, 2026 15:52
PR netj#23 review asked for a static compile instead of a python script that
parses and patches the live tmux binding at runtime (3-way python-tmux-sh
coupling). optmux/menu.py now keeps a literal copy of tmux's own
session/window/pane menu items and lets optmux.yaml's `menu:` section
redeclare each menu in full -- reordering, retitling, or remapping default
items by name, adding custom ones, with a bare "*" to pull in the rest of
tmux's defaults unchanged. This compiles to a static tmux.optmux-menu.conf
of bind/display-menu lines, replacing pane_menu.py's runtime list-keys/
source-file dance. optmux-defaults.yaml now ships the "New Window" pane
item through this mechanism.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
- Extract the shortcuts command-building logic (command/tmux/send_keys/
  new_window/float_window/zoom/detached/remain) into optmux/actions.py,
  shared by generate_shortcut_line (cli.py) and menu custom items
  (menu.py). Custom menu items now support the full shortcuts vocabulary
  instead of a stripped-down command/new_window-only subset.
- Replace \" escapes in the DEFAULT_MENUS tmux-syntax literals with
  triple-quoted strings.
- Replace f-string {{ }} brace-doubling in menu.py's bind-line builders
  and item compiler with %-formatting, since tmux's own syntax is brace-
  heavy and doubling every literal brace hurt readability.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…mples

- menu.py's implicit new_window default for custom items now only kicks
  in when the item names neither new_window nor float_window -- an item
  with float_window: true alone no longer trips the "mutually exclusive"
  warning against a default it never asked for. Caught while validating
  new doc examples against the real compiler.
- README: pull the shared command/tmux/send_keys/new_window/float_window/
  zoom/detached/remain vocabulary out into a dedicated "Action block"
  section referenced by both Shortcuts and Menu, instead of duplicating
  it. Add a menu example gallery (floating lazygit, send_keys test
  runner, detached background copy, retitle/remap a default item, and
  full manual enumeration to replace a default item's behavior) --
  every example is compiled and tmux-loaded as part of verifying this
  commit.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Shows a custom pane-menu item reusing an existing shortcut's command
(Edit README) and a retitled/remapped default window-menu item (Kill ->
Close Window / q), alongside the shortcuts: this file already
demonstrates. Verified via the real CLI (uv run optmux ./example.optmux.yaml)
that both compile into tmux.optmux-menu.conf and source cleanly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
tmux's choose-tree -Zw (normally only reachable via prefix w) opens an
interactive window/pane tree picker. Added as a session-menu item in
both the README's full-enumeration example and example.optmux.yaml,
under key 'T' to avoid colliding with the default menu's own 'w'
(New Window). Verified compiling with no warnings and sourcing into
real tmux, and via the actual CLI for example.optmux.yaml.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@netj

netj commented Aug 26, 2026

Copy link
Copy Markdown
Owner

check this out! I got a fully configurable menu to work via optmux.menu section in the yaml.

menu:
pane:
- key: e
title: Edit README
command: ${VISUAL:-${EDITOR:-vim}} README.md
- "*"
window:
- default: Kill
title: Close Window
key: q
- "*"
session:
- key: T
title: Windows/Panes
tmux: choose-tree -Zw
- "*"

image image image

@netj netj left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@jooddang lmk what u think!

suggest any ideas or submit improvements before I merge this later this week.

@jooddang

Copy link
Copy Markdown
Contributor Author

@jooddang lmk what u think!

suggest any ideas or submit improvements before I merge this later this week.

LGTM lol

Thank you!!!

@netj
netj merged commit 851c22c into netj:main Aug 28, 2026
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.

2 participants