Skip to content

Support prompt format strings for dynamic terminal titles#1684

Open
rolandwalker wants to merge 1 commit intomainfrom
RW/terminal-window-format-strings
Open

Support prompt format strings for dynamic terminal titles#1684
rolandwalker wants to merge 1 commit intomainfrom
RW/terminal-window-format-strings

Conversation

@rolandwalker
Copy link
Contributor

Description

  • tab title
  • window title
  • tmux window title (other multiplexers could be supported)
  • tmux pane title (other multiplexers could be supported)

Motivation: power users often have multiple connections open. We should help users keep track.

Tmux window-title example, showing the schema name:

last image

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the AUTHORS file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

@rolandwalker rolandwalker self-assigned this Mar 7, 2026
@github-actions
Copy link

github-actions bot commented Mar 7, 2026

Findings

  1. Potential crash when $TMUX is set but tmux is unavailable

    • File: mycli/main.py:1597
    • subprocess.run(['tmux', 'rename-window', title], ...) is not wrapped in try/except. If tmux is not on PATH (or unavailable in minimal/container envs), this raises FileNotFoundError and can crash interactive startup / \u flow.
    • Action: guard with shutil.which("tmux") and/or catch OSError around the call.
  2. Terminal escape injection risk in title sequences

    • Files: mycli/main.py:1574, mycli/main.py:1585, mycli/main.py:1614
    • Title text is inserted directly into OSC sequences after only strip_ansi(...). Control characters like BEL (\x07) or ST/ESC variants are not explicitly removed, so hostile prompt-derived values (e.g., schema/user/host content) could prematurely terminate OSC and inject terminal controls.
    • Action: sanitize title strings by removing all C0/C1 control chars (at minimum \x00-\x1F, \x7F, and ESC-related terminators) before printing OSC.
  3. Missing regression tests for new title code paths

    • Current PR only updates config fixture text (test/myclirc); no behavioral tests for the new helpers.
    • Action: add tests for:
      • no crash when $TMUX is set but tmux executable is missing,
      • control-character sanitization in generated titles,
      • set_all_external_titles() invocation points (initial prompt + \u database switch).

 * tab title
 * window title
 * tmux window title (other multiplexers could be supported)
 * tmux pane title (other multiplexers could be supported)

Motivation: power users often have multiple connections open.  We
should help users keep track.
@rolandwalker rolandwalker force-pushed the RW/terminal-window-format-strings branch from 55754e8 to 4209810 Compare March 7, 2026 14:56
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.

1 participant