← Back to Pull requests

fix(complete): complete paths after ~ and $VAR, and hidden file names #1692

Closed
unknown closed this pull request without merging on Dec 03, 2026 00:15 UTC
View on GitHub
unknown unknown commented on Dec 02, 2026 20:49 UTC
Author

Path completion returned nothing for words starting with ~, ~user, $VAR/ or ${VAR}/, and for hidden file names. It now completes them and keeps the prefix as typed:

$ usage complete-word --shell bash -s 'arg "[file]"' -- demo '~/bi'
~/bin/
$ usage complete-word --shell bash -s 'arg "[file]"' -- demo '$HOME/bi'
$HOME/bin/
$ usage complete-word --shell bash -s 'arg "[file]"' -- demo .hid
.hidden

This applies to the file fallback and to the path, file, dir, executable and extension-filtered completers.

  • Hidden names appear only once the segment being typed starts with ., including abbreviated parents (.hd/in → .hdir/inner).

  • A lone ~ or ~user completes to ~/. ~user is resolved through the system user database on Unix, and is not expanded on Windows. A $VAR is expanded only once a / follows it, and only if it is set and non-empty.

  • Shells strip quotes before calling usage, so a file literally named $HOME looks like the variable. The expansion is tried first, and the literal file answers if the expansion finds nothing.

  • zsh inserts the prefix unquoted and quotes the rest ($HOME/'My Docs/'), so it still expands. Only paths that completion looked up this way are left unquoted: a declared choice, completer output or literal file name spelled like a variable is still quoted whole. The generated zsh script now uses menu insertion for any quoted match, so regenerate zsh completion scripts to get that part.

  • A ~ in the middle of a word is not offered a home-directory path: behind --flag= or a sigil (@~/…) the shell leaves it unexpanded (zsh expands it after = only with MAGIC_EQUAL_SUBST). --flag=$HOME/… and @$HOME/… complete, as does --flag ~/….

  • A directory that exists as typed is now kept verbatim in candidates: ./vis completes to ./visible rather than visible, and an absolute path under the current directory stays absolute.

  • A word ending in .. completes to ../ instead of listing unrelated entries.
  • Fixes #1691

    Validation

    cargo test --all --all-features passed after accepting the zsh script snapshots, and mise run lint passed. Tab was also driven through completion-init in real shells under tmux:

  • zsh: ~/bi, ~/My, $HOME/bi, $HOME/My, ${HOME}/bi and .hid inserted a word that expanded to the intended path.

  • fish: ~/bi, ~/My, $HOME/bi, $HOME/My and .hid did too. fish has no ${HOME} syntax.

  • bash: ~/bi, $HOME/bi, ${HOME}/bi and .hid did too. Names containing spaces are still inserted unescaped by the bash script, which this PR does not change.
  • PowerShell, Nushell and Windows were not tried interactively.

    AI-assisted — Tool: Claude Code; model: anthropic/claude-sonnet-5-5; version: unavailable.

    🤖 Generated with Claude Code

    <!-- CURSOR_SUMMARY -->
    ---

    [!NOTE]

    Medium Risk

    Touches core completion and zsh insert/quoting across many code paths; wrong expandable metadata could break shell expansion or offer invalid paths behind flags/sigils.

    > Overview

    Path completion now resolves ~, ~user, $VAR/, and ${VAR}/ the way a shell would for lookup, but keeps the user’s spelling in candidates (e.g. ~/bin/, not a canonical home path). Unix resolves ~user via getpwnam_r; empty/unset vars and unknown users yield no expansion.

    > Filesystem scanning was refactored into search_path with text-based segment splitting: hidden dotfiles appear only after the typed segment starts with ., exact .//../ prefixes are preserved, .. completes to ../, and Windows drive-relative tokens split after C:.

    > zsh gets a third-column “insert” that leaves expandable prefixes unquoted so ~/$VAR still expand at runtime; declared choices and literals that merely look expandable stay fully quoted. Tilde-based lookups are dropped behind --flag= and sigils where shells won’t expand ~. Generated zsh scripts now enable menu mode when the insert contains any quote, not only a leading '.

    > <sup>Reviewed by Cursor Bugbot for commit 183987f4c87eb225ef76ca5c6781fc9ef725e276. Bugbot is set up for automated code reviews on this repo. Configure here.</sup>

    <!-- /CURSOR_SUMMARY -->

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

  • New Features

  • - Path completion supports home-directory and environment-variable prefixes, partial parent-directory segments, and explicit .. paths while preserving typed prefixes in suggestions.
    - Hidden entries appear when the typed path segment starts with a dot.
  • Bug Fixes

  • - Improved shell completion for expandable paths and suggestions containing apostrophes.
    - Unset or empty environment variables no longer produce path suggestions.
  • Tests

  • - Added coverage for path completion, hidden entries, candidate collisions, and shell-specific quoting.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 640 lines (+480 / -160) across 8 files Reviewer: jdx Review duration: 205m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 640 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.387
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1692"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 51.9% (MEDIUM) · Higher = larger blast radius
    51.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%
    Repository