Skip to content

Surface $CDPATH directories in cd argument completion#9444

Open
Faizanq wants to merge 4 commits intowarpdotdev:masterfrom
Faizanq:faizan/cdpath-completions
Open

Surface $CDPATH directories in cd argument completion#9444
Faizanq wants to merge 4 commits intowarpdotdev:masterfrom
Faizanq:faizan/cdpath-completions

Conversation

@Faizanq
Copy link
Copy Markdown
Contributor

@Faizanq Faizanq commented Apr 29, 2026

Description

Closes #373.

cd <Tab> now completes against directories under $CDPATH in addition to the current working directory, matching what the shell itself resolves when you cd to a relative path.

The bash and zsh bootstrap payloads now ship the CDPATH value alongside home_dir, path, etc. That value flows through BootstrappedValue -> SessionInfo -> Session::cdpath() and is exposed on PathCompletionContext::cdpath(). A new sorted_cd_directories helper wraps sorted_directories_relative_to: for each non-. entry in $CDPATH, it lists directory matches under that entry using a pwd-overriding context wrapper, deduped against the pwd-relative results.

The cd-specific path is opt-in to the cd command. Other Folders templates (tree, du, etc.) keep the existing pwd-only completion. Absolute paths (/foo), home-rooted paths (~/foo), and explicit relative prefixes (./foo, ../foo) skip CDPATH to match shell semantics.

Testing

Four new unit tests in crates/warp_completer/src/completer/engine/path_test.rs:

  • test_sorted_cd_directories_no_cdpath_matches_existing_behavior: without cdpath, the cd-aware path returns identical results to the current Folders path
  • test_sorted_cd_directories_includes_cdpath_entries: pwd entries first, then unique cdpath entries; duplicates deduped; non-directories filtered
  • test_sorted_cd_directories_ignores_cdpath_for_absolute_token: absolute path tokens bypass cdpath
  • test_sorted_cd_directories_skips_dot_entry_in_cdpath: . in cdpath is handled by the pwd-relative pass and not double-listed

All 13 path tests pass; clippy on warp and warp_completer is clean. I couldn't run the full warp lib test suite end-to-end locally (ran into a disk-space issue mid-build), relying on CI for the broader pass.

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI Agent Mode

Changelog Entries for Stable

CHANGELOG-IMPROVEMENT: cd <Tab> now completes against directories listed in $CDPATH, matching the resolution shells already perform.

Closes warpdotdev#373.

Pipe $CDPATH/$cdpath from the bash and zsh bootstrap payloads through to
the path completion engine, then have the cd-argument completer overlay
directories under each CDPATH entry on top of the pwd-relative results
so suggestions match what `cd` itself would resolve.

Behavior is opt-in to the cd command - other Folders templates
(e.g. for `tree`, `du`) keep the existing pwd-only completion. Absolute
paths, `~`-rooted paths, and explicit `./` / `../` prefixes skip CDPATH
to match shell semantics.

CHANGELOG-IMPROVEMENT
@cla-bot cla-bot Bot added the cla-signed label Apr 29, 2026
@oz-for-oss
Copy link
Copy Markdown
Contributor

oz-for-oss Bot commented Apr 29, 2026

@Faizanq

I'm starting a first review of this pull request.

I requested changes on this pull request and posted feedback.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

I'm re-reviewing this pull request in response to a review request.

You can view the conversation on Warp.

I completed the review and posted feedback on this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

oz-for-oss[bot]
oz-for-oss Bot previously requested changes Apr 29, 2026
Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

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

Overview

This PR threads CDPATH from the shell bootstrap through session context and uses it for cd folder completions in both completer engines.

Concerns

  • Relative CDPATH entries are not resolved against the shell's current working directory before directory listing, so valid settings like CDPATH=.. or CDPATH=src won't match shell cd behavior in local sessions.

Verdict

Found: 0 critical, 1 important, 0 suggestions

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

for entry in cdpath.split(':').filter(|e| !e.is_empty() && *e != ".") {
let override_ctx = CdpathOverrideContext {
inner: ctx,
cdpath_pwd: TypedPathBuf::from(entry),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ [IMPORTANT] Relative CDPATH entries are resolved by the shell against the current working directory, but storing entry directly makes list_directory_entries resolve values like .. or src relative to Warp's process/command context; join non-absolute CDPATH entries to ctx.pwd() before overriding pwd().

Faizanq added 2 commits April 30, 2026 10:24
Per shell semantics, CDPATH entries that aren't absolute are resolved
against the current working directory at cd time, and `~`/`~/...` is
expanded to $HOME. Previously each entry was passed straight to
TypedPathBuf::from, so settings like `CDPATH=src`, `CDPATH=..`, or
`CDPATH=~/code` produced no completions in local sessions.

Add resolve_cdpath_entry helper and three regression tests.
@Faizanq
Copy link
Copy Markdown
Contributor Author

Faizanq commented Apr 30, 2026

/oz-review

oz-for-oss[bot]
oz-for-oss Bot previously requested changes Apr 30, 2026
Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

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

Overview

This PR threads the shell CDPATH value through bootstrap/session state and uses it to add CDPATH-backed directory suggestions for cd arguments.

Concerns

  • The cd completer currently seeds current-directory results before CDPATH entries and dedupes by display, but bash/zsh resolve CDPATH-eligible cd targets by checking CDPATH before falling back to the current directory unless . or an empty entry is part of CDPATH. That can make completions come from a different tree than cd will resolve first.
  • Security pass: no direct security issue found in the changed code.

Verdict

Found: 0 critical, 1 important, 0 suggestions

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

matcher: MatchStrategy,
ctx: &dyn PathCompletionContext,
) -> Vec<MatchedSuggestion> {
let mut results = sorted_directories_relative_to(path, matcher, ctx).await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ [IMPORTANT] This seeds pwd-relative suggestions before CDPATH entries, but bash/zsh search CDPATH before falling back to pwd for CDPATH-eligible targets unless ./empty is in CDPATH; duplicate names and nested completions can therefore be sourced from the wrong tree compared with the cd that will run.

@captainsafia captainsafia added the external-contributor Indicates that a PR has been opened by someone outside the Warp team. label Apr 30, 2026 — with Warp Dev Github Integration
Bash and zsh search each $CDPATH entry in order; an empty or `.` entry
stands for the current directory at that position, and pwd is only used
as a fallback when no entry matches. The previous version always seeded
pwd results first and overlaid CDPATH dirs after, so completions
surfaced in a different order than `cd` would actually resolve them.

Iterate CDPATH in order, place pwd at the position of the first `.` or
empty entry (or append as fallback if absent), and dedupe by display so
the first occurrence wins. Update the existing tests to expect the new
order and add two more for empty-leading and dot-in-middle layouts.
@Faizanq
Copy link
Copy Markdown
Contributor Author

Faizanq commented May 1, 2026

/oz-review

@oz-for-oss
Copy link
Copy Markdown
Contributor

oz-for-oss Bot commented May 1, 2026

@Faizanq

I'm re-reviewing this pull request in response to a review request.

You can view the conversation on Warp.

I reviewed this pull request and requested human review from: @zachbai.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@oz-for-oss oz-for-oss Bot dismissed stale reviews from themself May 1, 2026 06:01

Oz no longer requests changes for this pull request after the latest automated review.

Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

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

Overview

This PR wires CDPATH from the bash/zsh bootstrap payload through session state into cd-specific directory completions, and extends the completer to search CDPATH entries in shell resolution order while preserving the existing pwd-only behavior for other folder templates.

Concerns

  • No blocking correctness, security, or error-handling concerns found in the inlined diff.

Verdict

Found: 0 critical, 0 important, 0 suggestions

Approve

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@oz-for-oss oz-for-oss Bot requested a review from zachbai May 1, 2026 06:01
Copy link
Copy Markdown
Contributor

@zachbai zachbai left a comment

Choose a reason for hiding this comment

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

Thanks for the change!

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

Labels

cla-signed external-contributor Indicates that a PR has been opened by someone outside the Warp team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CDPATH is not respected for completions

3 participants