Zsh completion tagging / grouping
C-enhancementS-triage
### Please complete the following tasks
- [x] I have searched the [discussions](https://github.com/clap-rs/clap/discussions)
- [x] I have searched the [open](https://github.com/clap-rs/clap/issues) and [rejected](https://github.com/clap-rs/clap/issues?q=is%3Aissue+label%3AS-wont-fix+is%3Aclosed) issues
### Clap Version
master
### Describe your use case
Currently, in zsh, completions are all shown in one group. For example:
```
$ jj commit -<TAB>
completing values
--at-operation -- Operation to load the repo at
--color -- When to colorize output
--config -- Additional configuration options (can be repeated)
--config-file -- Additional configuration files (can be repeated)
--debug -- Enable debug logging
--editor -- Open an editor to edit the change description
--ignore-immutable -- Allow rewriting immutable commits
--ignore-working-copy -- Don't snapshot the working copy, and don't update it
--no-pager -- Disable the pager
--quiet -- Silence non-primary command output
--tool -- Specify diff editor to be used (implies --interactive)
-h -- Print help (see more with '--help')
-i -- Interactively choose which changes to include in the current commit
-m -- The change description to use (don't open editor)
-R -- Path to repository to operate on
```
It would be nice to split these based on the completions for `commit` vs. those marked as global options, so it appears like so:
```
$ jj commit -<TAB>
completing global options
--at-operation -- Operation to load the repo at
--color -- When to colorize output
--config -- Additional configuration options (can be repeated)
--config-file -- Additional configuration files (can be repeated)
--debug -- Enable debug logging
--ignore-immutable -- Allow rewriting immutable commits
--ignore-working-copy -- Don't snapshot the working copy, and don't update it
--no-pager -- Disable the pager
--quiet -- Silence non-primary command output
-R -- Path to repository to operate on
completing command options
--editor -- Open an editor to edit the change description
--tool -- Specify diff editor to be used (implies --interactive)
-h -- Print help (see more with '--help')
-i -- Interactively choose which changes to include in the current commit
-m -- The change description to use (don't open editor)
```
### Describe the solution you'd like
I've hacked the [completion code that's generated](https://github.com/clap-rs/clap/blob/f0d30d961d26f8fb636b33242256fca73a717f77/clap_complete/src/env/shells.rs#L396-L397) like so to demonstrate this, specifically for `jj`'s global options.
```diff
other+=("$completion")
fi
done
+
+ local -a global_opts=(
+ -R
+ --repository
+ --ignore-working-copy
+ --ignore-immutable
+ --at-operation
+ --debug
+ --color
+ --quiet
+ --no-pager
+ --config
+ --config-file
+ )
+
+ local -a globals=()
+ local -a cmdopts=()
+
+ for completion in $other; do
+ local value="${completion%%:*}"
+
+ if (( ${global_opts[(Ie)$value]} )); then
+ globals+=("$completion")
+ else
+ cmdopts+=("$completion")
+ fi
+ done
+
- [[ -n $dirs ]] && _describe 'values' dirs -S '/' -r '/'
+ [[ -n $dirs ]] && _describe -t vals 'values' dirs -S '/' -r '/'
- [[ -n $other ]] && _describe 'values' other
+ [[ -n $globals ]] && _describe -t globals 'global options' globals
+ [[ -n $cmdopts ]] && _describe -t cmdopts 'command options' cmdopts
fi
}
```
This yields the desired outcome above. Obviously this isn't a solution - what we could do is pass through a list of global options into the completion generation and generate something like this. If it seems like a reasonable approach, I can put together a PR.
### Alternatives, if applicable
_No response_
### Additional Context
_No response_
0 条评论