Skip to content

Intelligent, width-aware directory shortening - #110

Merged
raiseCatError merged 1 commit into
devfrom
feature/v04-directory-shortening
Sep 25, 2026
Merged

raiseCatError merged 1 commit into
devfrom
feature/v04-directory-shortening

Conversation

@raiseCatError

Copy link
Copy Markdown
Owner

Refs #71

What

  • All path shortening lives in one policy in src/prompt/pathDisplay.ts. It is display only and never changes the cwd.
  • Levels are tried in order, and the prompt uses the first one whose whole row fits:
    0. full: ~/Projects/work/notMyShell/src/prompt
    1. parents above the repo abbreviated: ~/P/w/notMyShell/src/prompt
    2. directories inside the repo abbreviated too: ~/P/w/notMyShell/s/prompt
    3. runs collapsed: …/notMyShell/…/prompt
    4. final directory only: …/prompt (the project module already names the repo)
  • The path shortens before any module is dropped, so the branch stays visible longer on narrow terminals.
  • Abbreviations are the shortest unambiguous, case-insensitive prefix among sibling directories. They are resolved asynchronously next to the prompt context with bounded readdir of ancestors, and fall back to the first character. Hidden directories keep their dot.
  • The repository root name and the final directory are never abbreviated. HOME stays ~, and a sibling of HOME is not treated as HOME.
  • PromptContext gains root and pathAbbreviations. Prompt snapshots keep the full, width-independent path, so history stays stable.

Verification

npm run build, npm run typecheck, npm test, git diff --check. tests/pathDisplay.test.ts covers every level, non-repo paths, HOME, /, trailing slashes, hidden directories, unique-prefix resolution against a real temporary tree, the exact-width sweep 20–160, and snapshot stability.

The behavior is fully deterministic and tested at the string level, so no terminal-specific behavior is involved.

One central path-display policy (src/prompt/pathDisplay.ts) replaces the
ad-hoc HOME substitution. The live prompt tries shortening levels in
order and uses the first whose full prompt fits: parents above the
repository abbreviate to their shortest unambiguous sibling prefix,
then directories inside the repository, then runs collapse to an
ellipsis, then only the final directory remains. The repository name
and final directory stay whole, HOME stays ~, and prompt snapshots keep
the full width-independent path. Abbreviations are resolved
asynchronously alongside the prompt context; nothing changes the cwd.
@raiseCatError raiseCatError added area:prompt Prompt and context display type:feature New feature or improvement labels Sep 25, 2026
@raiseCatError
raiseCatError merged commit 0e93348 into dev Sep 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:prompt Prompt and context display type:feature New feature or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant