Skip to content

[Console] Fix fish completion script #46220

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

Merged
merged 1 commit into from
Apr 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/Symfony/Component/Console/Command/DumpCompletionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,40 @@ protected function configure()
$commandName = basename($fullCommand);
$fullCommand = realpath($fullCommand) ?: $fullCommand;

$shell = $this->guessShell();
[$rcFile, $completionFile] = match ($shell) {
'fish' => ['~/.config/fish/config.fish', "/etc/fish/completions/$commandName.fish"],
default => ['~/.bashrc', "/etc/bash_completion.d/$commandName"],
};

$this
->setHelp(<<<EOH
The <info>%command.name%</> command dumps the shell completion script required
to use shell autocompletion (currently only bash completion is supported).
to use shell autocompletion (currently, bash and fish completion is supported).

<comment>Static installation
-------------------</>

Dump the script to a global completion file and restart your shell:

<info>%command.full_name% bash | sudo tee /etc/bash_completion.d/${commandName}</>
<info>%command.full_name% {$shell} | sudo tee {$completionFile}</>

Or dump the script to a local file and source it:

<info>%command.full_name% bash > completion.sh</>
<info>%command.full_name% {$shell} > completion.sh</>

<comment># source the file whenever you use the project</>
<info>source completion.sh</>

<comment># or add this line at the end of your "~/.bashrc" file:</>
<comment># or add this line at the end of your "{$rcFile}" file:</>
<info>source /path/to/completion.sh</>

<comment>Dynamic installation
--------------------</>

Add this to the end of your shell configuration file (e.g. <info>"~/.bashrc"</>):
Add this to the end of your shell configuration file (e.g. <info>"{$rcFile}"</>):

<info>eval "$(${fullCommand} completion bash)"</>
<info>eval "$({$fullCommand} completion {$shell})"</>
EOH
)
->addArgument('shell', InputArgument::OPTIONAL, 'The shell type (e.g. "bash"), the value of the "$SHELL" env var will be used if this is not given', null, $this->getSupportedShells(...))
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Resources/completion.fish
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

function _sf_{{ COMMAND_NAME }}
set sf_cmd (commandline -o)
set c (math (count (commandline -oc))) - 1)
set c (count (commandline -oc))

set completecmd "$sf_cmd[1]" "_complete" "-sfish" "-S{{ VERSION }}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public function testDescribeCommand(Command $command, $expectedDescription)
/** @dataProvider getDescribeApplicationTestData */
public function testDescribeApplication(Application $application, $expectedDescription)
{
// the "completion" command has dynamic help information depending on the shell
$application->find('completion')->setHelp('');

$this->assertDescription($expectedDescription, $application);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"completion [--debug] [--] [<shell>]"
],
"description": "Dump the shell completion script",
"help": "The <info>completion</> command dumps the shell completion script required\nto use shell autocompletion (currently only bash completion is supported).\n\n<comment>Static installation\n-------------------</>\n\nDump the script to a global completion file and restart your shell:\n\n <info>%%PHP_SELF%% completion bash | sudo tee /etc/bash_completion.d/%%COMMAND_NAME%%</>\n\nOr dump the script to a local file and source it:\n\n <info>%%PHP_SELF%% completion bash > completion.sh</>\n\n <comment># source the file whenever you use the project</>\n <info>source completion.sh</>\n\n <comment># or add this line at the end of your \"~/.bashrc\" file:</>\n <info>source /path/to/completion.sh</>\n\n<comment>Dynamic installation\n--------------------</>\n\nAdd this to the end of your shell configuration file (e.g. <info>\"~/.bashrc\"</>):\n\n <info>eval \"$(%%PHP_SELF_FULL%% completion bash)\"</>",
"help": "Dump the shell completion script",
"definition": {
"arguments": {
"shell": {
Expand Down
27 changes: 1 addition & 26 deletions src/Symfony/Component/Console/Tests/Fixtures/application_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,7 @@ Dump the shell completion script

* `completion [--debug] [--] [<shell>]`

The completion command dumps the shell completion script required
to use shell autocompletion (currently only bash completion is supported).

Static installation
-------------------

Dump the script to a global completion file and restart your shell:

%%PHP_SELF%% completion bash | sudo tee /etc/bash_completion.d/%%COMMAND_NAME%%

Or dump the script to a local file and source it:

%%PHP_SELF%% completion bash > completion.sh

# source the file whenever you use the project
source completion.sh

# or add this line at the end of your "~/.bashrc" file:
source /path/to/completion.sh

Dynamic installation
--------------------

Add this to the end of your shell configuration file (e.g. "~/.bashrc"):

eval "$(%%PHP_SELF_FULL%% completion bash)"
Dump the shell completion script

### Arguments

Expand Down
27 changes: 1 addition & 26 deletions src/Symfony/Component/Console/Tests/Fixtures/application_1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,7 @@
<usage>completion [--debug] [--] [&lt;shell&gt;]</usage>
</usages>
<description>Dump the shell completion script</description>
<help>The &lt;info&gt;completion&lt;/&gt; command dumps the shell completion script required
to use shell autocompletion (currently only bash completion is supported).

&lt;comment&gt;Static installation
-------------------&lt;/&gt;

Dump the script to a global completion file and restart your shell:

&lt;info&gt;%%PHP_SELF%% completion bash | sudo tee /etc/bash_completion.d/%%COMMAND_NAME%%&lt;/&gt;

Or dump the script to a local file and source it:

&lt;info&gt;%%PHP_SELF%% completion bash &gt; completion.sh&lt;/&gt;

&lt;comment&gt;# source the file whenever you use the project&lt;/&gt;
&lt;info&gt;source completion.sh&lt;/&gt;

&lt;comment&gt;# or add this line at the end of your "~/.bashrc" file:&lt;/&gt;
&lt;info&gt;source /path/to/completion.sh&lt;/&gt;

&lt;comment&gt;Dynamic installation
--------------------&lt;/&gt;

Add this to the end of your shell configuration file (e.g. &lt;info&gt;"~/.bashrc"&lt;/&gt;):

&lt;info&gt;eval "$(%%PHP_SELF_FULL%% completion bash)"&lt;/&gt;</help>
<help>Dump the shell completion script</help>
<arguments>
<argument name="shell" is_required="0" is_array="0">
<description>The shell type (e.g. "bash"), the value of the "$SHELL" env var will be used if this is not given</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"completion [--debug] [--] [<shell>]"
],
"description": "Dump the shell completion script",
"help": "The <info>completion</> command dumps the shell completion script required\nto use shell autocompletion (currently only bash completion is supported).\n\n<comment>Static installation\n-------------------</>\n\nDump the script to a global completion file and restart your shell:\n\n <info>%%PHP_SELF%% completion bash | sudo tee /etc/bash_completion.d/%%COMMAND_NAME%%</>\n\nOr dump the script to a local file and source it:\n\n <info>%%PHP_SELF%% completion bash > completion.sh</>\n\n <comment># source the file whenever you use the project</>\n <info>source completion.sh</>\n\n <comment># or add this line at the end of your \"~/.bashrc\" file:</>\n <info>source /path/to/completion.sh</>\n\n<comment>Dynamic installation\n--------------------</>\n\nAdd this to the end of your shell configuration file (e.g. <info>\"~/.bashrc\"</>):\n\n <info>eval \"$(%%PHP_SELF_FULL%% completion bash)\"</>",
"help": "Dump the shell completion script",
"definition": {
"arguments": {
"shell": {
Expand Down
27 changes: 1 addition & 26 deletions src/Symfony/Component/Console/Tests/Fixtures/application_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,7 @@ Dump the shell completion script

* `completion [--debug] [--] [<shell>]`

The completion command dumps the shell completion script required
to use shell autocompletion (currently only bash completion is supported).

Static installation
-------------------

Dump the script to a global completion file and restart your shell:

%%PHP_SELF%% completion bash | sudo tee /etc/bash_completion.d/%%COMMAND_NAME%%

Or dump the script to a local file and source it:

%%PHP_SELF%% completion bash > completion.sh

# source the file whenever you use the project
source completion.sh

# or add this line at the end of your "~/.bashrc" file:
source /path/to/completion.sh

Dynamic installation
--------------------

Add this to the end of your shell configuration file (e.g. "~/.bashrc"):

eval "$(%%PHP_SELF_FULL%% completion bash)"
Dump the shell completion script

### Arguments

Expand Down
27 changes: 1 addition & 26 deletions src/Symfony/Component/Console/Tests/Fixtures/application_2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,7 @@
<usage>completion [--debug] [--] [&lt;shell&gt;]</usage>
</usages>
<description>Dump the shell completion script</description>
<help>The &lt;info&gt;completion&lt;/&gt; command dumps the shell completion script required
to use shell autocompletion (currently only bash completion is supported).

&lt;comment&gt;Static installation
-------------------&lt;/&gt;

Dump the script to a global completion file and restart your shell:

&lt;info&gt;%%PHP_SELF%% completion bash | sudo tee /etc/bash_completion.d/%%COMMAND_NAME%%&lt;/&gt;

Or dump the script to a local file and source it:

&lt;info&gt;%%PHP_SELF%% completion bash &gt; completion.sh&lt;/&gt;

&lt;comment&gt;# source the file whenever you use the project&lt;/&gt;
&lt;info&gt;source completion.sh&lt;/&gt;

&lt;comment&gt;# or add this line at the end of your "~/.bashrc" file:&lt;/&gt;
&lt;info&gt;source /path/to/completion.sh&lt;/&gt;

&lt;comment&gt;Dynamic installation
--------------------&lt;/&gt;

Add this to the end of your shell configuration file (e.g. &lt;info&gt;"~/.bashrc"&lt;/&gt;):

&lt;info&gt;eval "$(%%PHP_SELF_FULL%% completion bash)"&lt;/&gt;</help>
<help>Dump the shell completion script</help>
<arguments>
<argument name="shell" is_required="0" is_array="0">
<description>The shell type (e.g. "bash"), the value of the "$SHELL" env var will be used if this is not given</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,7 @@ Dump the shell completion script

* `completion [--debug] [--] [<shell>]`

The completion command dumps the shell completion script required
to use shell autocompletion (currently only bash completion is supported).

Static installation
-------------------

Dump the script to a global completion file and restart your shell:

%%PHP_SELF%% completion bash | sudo tee /etc/bash_completion.d/%%COMMAND_NAME%%

Or dump the script to a local file and source it:

%%PHP_SELF%% completion bash > completion.sh

# source the file whenever you use the project
source completion.sh

# or add this line at the end of your "~/.bashrc" file:
source /path/to/completion.sh

Dynamic installation
--------------------

Add this to the end of your shell configuration file (e.g. "~/.bashrc"):

eval "$(%%PHP_SELF_FULL%% completion bash)"
Dump the shell completion script

### Arguments

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy