Please complete the following tasks
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 the jj commit command 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)
As a user I can then see the five options relevant to the commit command without needing to filter through global options in my head.
Describe the solution you'd like
I've hacked the completion code that's generated like so to demonstrate this, specifically for jj's global options.
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
Somewhat related to #5355, except this is completion of- and grouping-of global options, rather than hiding.
Please complete the following tasks
Clap Version
master
Describe your use case
Currently, in zsh, completions are all shown in one group. For example:
It would be nice to split these based on the completions for the
jj commitcommand vs. those marked as global options, so it appears like so:As a user I can then see the five options relevant to the
commitcommand without needing to filter through global options in my head.Describe the solution you'd like
I've hacked the completion code that's generated like so to demonstrate this, specifically for
jj's global options.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
Somewhat related to #5355, except this is completion of- and grouping-of global options, rather than hiding.