Skip to content

feat(config): configurable window-title and tab-title format strings#798

Open
HermeticOrmus wants to merge 1 commit into
pop-os:masterfrom
HermeticOrmus:feature/window-title-format
Open

feat(config): configurable window-title and tab-title format strings#798
HermeticOrmus wants to merge 1 commit into
pop-os:masterfrom
HermeticOrmus:feature/window-title-format

Conversation

@HermeticOrmus
Copy link
Copy Markdown

Why

Refs #720. cosmic-term already ingests OSC 7 (working directory) for the new-tab-cwd-inherit feature, but never surfaces it in the window or tab title. Users who want to see what directory the active shell is in have to run `pwd`. Ghostty's default title format includes the cwd; alacritty supports `window.title` formatting; cosmic-term should match.

What changed

`src/config.rs` gains two fields:

  • `window_title_format: String` — default `"{title} — {app}"` (preserves current behaviour)
  • `tab_title_format: String` — default `""` (empty = use the shell-set title verbatim, current behaviour)

Both accept the placeholders `{title}`, `{cwd}`, `{cwd_basename}`, `{app}`.

`update_title()` in `src/main.rs` calls a new `config::render_title_format` helper to substitute. Defaults reproduce the existing UX exactly — no behaviour change unless the user opts in.

Example user config that mirrors Ghostty's default:

```ron
window_title_format: "{cwd_basename} — {title}",
tab_title_format: "{cwd_basename}",
```

How to test

```bash
cargo build --bin cosmic-term
cargo test --bin cosmic-term config::tests::

6 tests: substitutes title+app, substitutes cwd, cwd_basename, missing cwd,

unknown placeholders left alone, substitution order edge case

```

All 6 pass locally on Linux x64.

Manual:

  • Default config: window title shows `bash — COSMIC Terminal` (unchanged).
  • Set `window_title_format: "{cwd_basename} — {title}"`: window title becomes `cosmic-term — bash` while cwd matches.
  • Unknown placeholders are left literal.

Notes

  • `cwd_basename` is substituted before `cwd` in the renderer because `{cwd_basename}` literally contains the substring `cwd}`. Test `cwd_basename_must_match_before_cwd_to_avoid_partial_replacement` guards this.
  • Active CWD is read via the existing `Self::active_terminal_working_directory()`, which uses `/proc/<shell_pid>/cwd` — no new syscalls beyond what was already happening for the cwd-inherit path.
  • Branch is based off commit 7ce2974 to match the fork's master baseline (HermeticOrmus/cosmic-term hasn't been rebased onto recent upstream master); the diff against pop-os/cosmic-term/master should still be minimal — just the two files in `src/`.

Adds Config.window_title_format (default `"{title} — {app}"`) and
Profile-overridable Config.tab_title_format (default empty = use the
shell-set title verbatim). Substitution placeholders: {title}, {cwd},
{cwd_basename}, {app}.

The current working directory was already plumbed via OSC 7 into
Self::active_terminal_working_directory(); this surfaces it in the
title bar so the format can include it. Default behaviour unchanged.

Useful for users who want the cwd visible without running `pwd` (e.g.
`window_title_format = "{cwd_basename} — {title}"` matches the Ghostty
default).

Refs: pop-os#720

6 unit tests for render_title_format covering known placeholders,
unknown placeholders left alone, missing-cwd, and the edge case where
{cwd_basename} contains "cwd}" so substitution order matters.
@jackpot51
Copy link
Copy Markdown
Member

The PR template is mandatory

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