Skip to content

fix(complete): Trailing space after zsh directory completions#6203

Merged
epage merged 1 commit intoclap-rs:masterfrom
jpgrayson:fix/zsh-space-after-dir-completions
Dec 30, 2025
Merged

fix(complete): Trailing space after zsh directory completions#6203
epage merged 1 commit intoclap-rs:masterfrom
jpgrayson:fix/zsh-space-after-dir-completions

Conversation

@jpgrayson
Copy link
Contributor

zsh dynamic completions would add a trailing space after all completions, including directories. This prevented natural path completion. Users had to delete the trailing space before continuing to type or tab-complete within the directory.

The fix is for the dynamic completion script to separate completions into directories and non-directories, and providing the directory completions to zsh with a different _describe invocation.

For directories:

  1. Strip the trailing slash from the completion value
  2. Let zsh add it back as a suffix using _describe -S '/'
  3. Also provide -r '/' to make the slash auto-removable when typing '/'

This makes dynamic path completions reasonably emulate zsh-native file completions.

This matches the behavior already implemented for bash completions which uses 'compopt -o nospace' to achieve the same result.

Fixes: #6178
Ref: jj-vcs/jj#5582

@jpgrayson jpgrayson force-pushed the fix/zsh-space-after-dir-completions branch from 2edf627 to 77be839 Compare December 30, 2025 05:27
zsh dynamic completions would add a trailing space after all
completions, including directories. This prevented natural path
completion. Users had to delete the trailing space before continuing to
type or tab-complete within the directory.

The fix is for the dynamic completion script to separate completions
into directories and non-directories, and providing the directory
completions to zsh with a different _describe invocation.

For directories:
1. Strip the trailing slash from the completion value
2. Let zsh add it back as a suffix using `_describe -S '/'`
3. Also provide `-r '/'` to make the slash auto-removable when typing '/'

This makes dynamic path completions reasonably emulate zsh-native file
completions.

This matches the behavior already implemented for bash completions which
uses 'compopt -o nospace' to achieve the same result.

Fixes: clap-rs#6178
Ref: jj-vcs/jj#5582
@jpgrayson jpgrayson force-pushed the fix/zsh-space-after-dir-completions branch from 77be839 to 5571b83 Compare December 30, 2025 05:32
@jpgrayson jpgrayson changed the title fix(complete): zsh trailing space after directory completions fix(complete): Trailing space after zsh directory completions Dec 30, 2025
@epage
Copy link
Member

epage commented Dec 30, 2025

Thanks!

Really look forward to someone diving into #5587 so we can remove all of these hacks and have better control over this.

@epage epage merged commit ab4f438 into clap-rs:master Dec 30, 2025
25 checks passed
@jpgrayson jpgrayson deleted the fix/zsh-space-after-dir-completions branch January 9, 2026 16:24
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.

Completion of FilePath adds space in zsh

2 participants