-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Zsh shell autocompletions #43970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zsh shell autocompletions #43970
Conversation
maybe a false positive in fabbot ci for typo? the |
Yeah, this definitely looks like a false positive |
@stof i used auto sync upstream from github ui, so any idea how can i remove the Merge commit now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that you added comments in the script; especially since we don't have a way to write test on it for now.
I have a suggestion to avoid shell-specific code in Application
class.
$suggestions->suggestValues(array_filter(array_map(function (Command $command) { | ||
return $command->isHidden() ? null : $command->getName(); | ||
$suggestions->suggestValues(array_filter(array_map(function (Command $command) use ($input) { | ||
return $command->isHidden() ? null : $command->getName().($input->isShell('zsh') ? "\t".$command->getDescription() : ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing if shell is zsh seems very specific for this place.
We could use a DTO. The ZshCompletionOutput
would format the value with its specificities. By implementing the __toString
method, the BashCompletionOutput
would not require any change.
namespace Symfony\Component\Console\Completion;
final class SuggestedValue {
private $value;
private $description;
public function __construct(string $value, string $description = null) {
$this->value = $value;
$this->description = $description;
}
public function __toString(): string {
return $this->value;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or maybe some abstraction to tell/handle if the shell supports description for autocompleted suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would add complexity in all commands that implements completion. I'm not sure this is something we want.
Each command should set suggestions values, optionally with a description using this DTO.
|
||
# Ensure atleast 1 input | ||
if [ "${i}" = "" ]; then | ||
requestComp="${requestComp} -i\" \"" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes the CompletionInput::getCurrentValue()
equals to a space? it would be better to skip the value entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it still requires -i option equal or 1 more than -c option that's why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then, does it work with an empty string?
requestComp="${requestComp} -i\" \"" | |
requestComp="${requestComp} -i\"\" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no it can't be empty
Co-authored-by: JΓ©rΓ΄me Tamarelle <[email protected]>
This PR was merged into the 6.2 branch. Discussion ---------- [Console] Zsh shell autocompletion | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #43592 | License | MIT | Doc PR | todo Continuation of #43970 * Rebased, including bug fixes. * Added description to completion values, implemented for commands and options names. (should be used for fish also) ``` % bin/console [TAB] about -- Display information about the current project assets:install -- Install bundle's web assets under a public directory cache:clear -- Clear the cache cache:pool:clear -- Clear cache pools ``` Commits ------- 3c2e1a4 Finish Zsh completion 405f207 Add zsh completion
Usage
Setup/Install
In
zsh
terminal run:which will add dumped zsh completion helper in first fpath (zsh's functions autoload path).
Then reload shell or just do
source "$fpath[1]/console"
.Here's a simple script
sfzsh
that I'm using while adding the zsh autocompletion support as a testbed:Toggle code
Autocomplete commands
Autocomplete options
Autocomplete option values
Autocomplete args