Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
adhocore wants to merge10 commits intosymfony:6.2fromadhocore:5.4
Closed

Zsh shell autocompletions#43970

adhocore wants to merge10 commits intosymfony:6.2fromadhocore:5.4

Conversation

@adhocore
Copy link
Contributor

@adhocoreadhocore commentedNov 9, 2021
edited
Loading

QA
Branch?5.4
Bug fix?no
New feature?yes
Deprecations?no
TicketsFix#43592
LicenseMIT
Doc PR-

Usage

Setup/Install

Inzsh terminal run:

bin/console completion zsh>"$fpath[1]/console"

which will add dumped zsh completion helper in first fpath (zsh's functions autoload path).
Then reload shell or just dosource "$fpath[1]/console".


Here's a simple scriptsfzsh that I'm using while adding thezsh autocompletion support as a testbed:

Toggle code

#!/bin/env php<?phpuseSymfony\Component\Console\Application;useSymfony\Component\Console\Command\Command;useSymfony\Component\Console\Completion\CompletionInput;useSymfony\Component\Console\Completion\CompletionSuggestions;useSymfony\Component\Console\Descriptor\ApplicationDescription;useSymfony\Component\Console\Helper\DescriptorHelper;useSymfony\Component\Console\Input\InputInterface;useSymfony\Component\Console\Input\InputArgument;useSymfony\Component\Console\Input\InputOption;useSymfony\Component\Console\Output\OutputInterface;putenv('SYMFONY_COMPLETION_DEBUG=1');$app =newApplication('sfzsh','0.0.1');// test1$app->add(newclass()extends Command {protectedstatic$defaultName ='test1';protectedstatic$defaultDescription ='Test one cmd';protectedfunctionconfigure():void    {$this            ->addOption('t1o1','1', InputOption::VALUE_REQUIRED,'t1o1 str val')            ->addOption('t1o2','2', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,'t1o2 array val')            ->addArgument('php', InputArgument::REQUIRED,'PHP file in current dir')        ;    }protectedfunctionexecute(InputInterface$input,OutputInterface$output):int    {return0;    }publicfunctioncomplete(CompletionInput$input,CompletionSuggestions$suggestions):void    {if ($input->mustSuggestOptionValuesFor('t1o1')) {$suggestions->suggestValues(['t1o1.v1','t1o1.v2']);return;        }if ($input->mustSuggestOptionValuesFor('t1o2')) {$suggestions->suggestValues(['t1o2.v1','t1o2.v2']);return;        }if ($input->mustSuggestArgumentValuesFor('php')) {$suggestions->suggestValues([system('ls -1 *.php')]);return;        }    }});// test2$app->add(newclass()extends Command {protectedstatic$defaultName ='test2';protectedstatic$defaultDescription ='Test two cmd';protectedfunctionconfigure():void    {$this            ->addOption('t2o1','1', InputOption::VALUE_REQUIRED,'t2o1 str val')            ->addOption('t2o2','2', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,'t2o2 array val')            ->addArgument('dir', InputArgument::REQUIRED,'subdir in current dir')        ;    }protectedfunctionexecute(InputInterface$input,OutputInterface$output):int    {return0;    }publicfunctioncomplete(CompletionInput$input,CompletionSuggestions$suggestions):void    {if ($input->mustSuggestOptionValuesFor('t2o1')) {$suggestions->suggestValues(['t2o1.v1','t2o1.v2']);return;        }if ($input->mustSuggestOptionValuesFor('t2o2')) {$suggestions->suggestValues(['t2o2.v1','t2o2.v2']);return;        }if ($input->mustSuggestArgumentValuesFor('dir')) {$suggestions->suggestValues([system('ls -1d */')]);return;        }    }});$app->run();

sfzsh completion zsh>"${fpath[1]}/sfzsh"."${fpath[1]}/sfzsh"

Autocomplete commands

sfzsh [TAB]

image

Shortlisting works too:sfzsh te[TAB] autocompletes fortest1 andtest2

Fuzzy match works too:sfzsh t1[TAB] autocompletestest1

Autocomplete options

 sfzsh test1 --[TAB]

image

Autocomplete option values

sfzsh test1 --t1o1 [TAB]

image

= separator works too:sfzsh test1 --t1o1=[TAB]

Autocomplete args

sfzsh test1 [TAB]

|_ (autocompletes *.php files in current dir)

sfzsh test2 [TAB]

|_ (autocompletes subdirs in current dir)

@adhocore
Copy link
ContributorAuthor

maybe a false positive in fabbot ci for typo?
"help": "The <info>completion</> command dumps the shell completion script required\nto
is suggested to be
"help": "The <info>completion</> command dumps the shell completion script required\not

the\n is LF and notnot

@stof
Copy link
Member

stof commentedNov 9, 2021

Yeah, this definitely looks like a false positive

@adhocore
Copy link
ContributorAuthor

@stof i used auto sync upstream from github ui, so any idea how can i remove the Merge commit now?

@stof
Copy link
Member

stof commentedNov 9, 2021

Copy link
Member

@GromNaNGromNaN left a 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 inApplication 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() :'');
Copy link
Member

@GromNaNGromNaNNov 10, 2021
edited
Loading

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. TheZshCompletionOutput would format the value with its specificities. By implementing the__toString method, theBashCompletionOutput would not require any change.

namespaceSymfony\Component\Console\Completion;finalclass SuggestedValue {private$value;private$description;publicfunction__construct(string$value,string$description =null) {$this->value =$value;$this->description =$description;    }publicfunction__toString():string {return$this->value;    }}

Copy link
ContributorAuthor

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

Copy link
Member

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.

chalasr reacted with thumbs up emoji

# Ensure atleast 1 input
if ["${i}"="" ];then
requestComp="${requestComp} -i\"\""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

That makes theCompletionInput::getCurrentValue() equals to a space? it would be better to skip the value entirely.

Copy link
ContributorAuthor

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

Copy link
Member

@GromNaNGromNaNNov 10, 2021
edited
Loading

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?

Suggested change
requestComp="${requestComp} -i\"\""
requestComp="${requestComp} -i\"\"

Copy link
ContributorAuthor

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 <jerome@tamarelle.net>
@fabpotfabpot modified the milestones:5.4,6.1Nov 16, 2021
@fabpotfabpot modified the milestones:6.1,6.2May 20, 2022
@fabpot
Copy link
Member

@adhocore@GromNaN What's the status of this PR?
I see that, at least, it needs to be rebased on current 6.2.

GromNaN reacted with thumbs up emoji

@GromNaN
Copy link
Member

GromNaN commentedJul 21, 2022
edited
Loading

Hello@adhocore. I created a new PR to rebase your work and change the way descriptions are output.
Please feel free to review#47018.

adhocore reacted with hooray emoji

fabpot added a commit that referenced this pull requestJul 22, 2022
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        | todoContinuation 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 projectassets:install              -- Install bundle's web assets under a public directorycache:clear                 -- Clear the cachecache:pool:clear            -- Clear cache pools```Commits-------3c2e1a4 Finish Zsh completion405f207 Add zsh completion
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@GromNaNGromNaNGromNaN requested changes

@chalasrchalasrAwaiting requested review from chalasrchalasr is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

6.2

Development

Successfully merging this pull request may close these issues.

[Console] Implement completion for zsh

5 participants

@adhocore@stof@fabpot@GromNaN@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp