diff --git a/src/Symfony/Component/Console/Command/DumpCompletionCommand.php b/src/Symfony/Component/Console/Command/DumpCompletionCommand.php index 7597a9e2cc651..0b059f3eddcdf 100644 --- a/src/Symfony/Component/Console/Command/DumpCompletionCommand.php +++ b/src/Symfony/Component/Console/Command/DumpCompletionCommand.php @@ -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(<<%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). Static installation ------------------- Dump the script to a global completion file and restart your shell: - %command.full_name% bash | sudo tee /etc/bash_completion.d/${commandName} + %command.full_name% {$shell} | sudo tee {$completionFile} Or dump the script to a local file and source it: - %command.full_name% bash > completion.sh + %command.full_name% {$shell} > completion.sh # source the file whenever you use the project source completion.sh - # or add this line at the end of your "~/.bashrc" file: + # or add this line at the end of your "{$rcFile}" file: source /path/to/completion.sh Dynamic installation -------------------- -Add this to the end of your shell configuration file (e.g. "~/.bashrc"): +Add this to the end of your shell configuration file (e.g. "{$rcFile}"): - eval "$(${fullCommand} completion bash)" + 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(...)) diff --git a/src/Symfony/Component/Console/Resources/completion.fish b/src/Symfony/Component/Console/Resources/completion.fish index 6566c58a3f9ea..680d180e03843 100644 --- a/src/Symfony/Component/Console/Resources/completion.fish +++ b/src/Symfony/Component/Console/Resources/completion.fish @@ -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 }}" diff --git a/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php index 97199fb34573e..2095266965ef7 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php @@ -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); } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.json b/src/Symfony/Component/Console/Tests/Fixtures/application_1.json index c4e98a957ba0d..db3c250fff003 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.json +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.json @@ -120,7 +120,7 @@ "completion [--debug] [--] []" ], "description": "Dump the shell completion script", - "help": "The completion command dumps the shell completion script required\nto use shell autocompletion (currently only bash completion is supported).\n\nStatic installation\n-------------------\n\nDump the script to a global completion file and restart your shell:\n\n %%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 %%PHP_SELF%% completion bash > completion.sh\n\n # source the file whenever you use the project\n source completion.sh\n\n # or add this line at the end of your \"~/.bashrc\" file:\n source /path/to/completion.sh\n\nDynamic installation\n--------------------\n\nAdd this to the end of your shell configuration file (e.g. \"~/.bashrc\"):\n\n eval \"$(%%PHP_SELF_FULL%% completion bash)\"", + "help": "Dump the shell completion script", "definition": { "arguments": { "shell": { diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.md b/src/Symfony/Component/Console/Tests/Fixtures/application_1.md index 0bef4ce3148e0..bb722c07704b5 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.md @@ -14,32 +14,7 @@ Dump the shell completion script * `completion [--debug] [--] []` -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 diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml b/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml index d56164ef875f5..9010a68a17a36 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml @@ -53,32 +53,7 @@ completion [--debug] [--] [<shell>] Dump the shell completion script - The <info>completion</> command dumps the shell completion script required - to use shell autocompletion (currently only bash completion is supported). - - <comment>Static installation - -------------------</> - - Dump the script to a global completion file and restart your shell: - - <info>%%PHP_SELF%% completion bash | sudo tee /etc/bash_completion.d/%%COMMAND_NAME%%</> - - Or dump the script to a local file and source it: - - <info>%%PHP_SELF%% completion bash > 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:</> - <info>source /path/to/completion.sh</> - - <comment>Dynamic installation - --------------------</> - - Add this to the end of your shell configuration file (e.g. <info>"~/.bashrc"</>): - - <info>eval "$(%%PHP_SELF_FULL%% completion bash)"</> + Dump the shell completion script The shell type (e.g. "bash"), the value of the "$SHELL" env var will be used if this is not given diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.json b/src/Symfony/Component/Console/Tests/Fixtures/application_2.json index 7cd6deddcec4d..0938b3ed3c535 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.json +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.json @@ -124,7 +124,7 @@ "completion [--debug] [--] []" ], "description": "Dump the shell completion script", - "help": "The completion command dumps the shell completion script required\nto use shell autocompletion (currently only bash completion is supported).\n\nStatic installation\n-------------------\n\nDump the script to a global completion file and restart your shell:\n\n %%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 %%PHP_SELF%% completion bash > completion.sh\n\n # source the file whenever you use the project\n source completion.sh\n\n # or add this line at the end of your \"~/.bashrc\" file:\n source /path/to/completion.sh\n\nDynamic installation\n--------------------\n\nAdd this to the end of your shell configuration file (e.g. \"~/.bashrc\"):\n\n eval \"$(%%PHP_SELF_FULL%% completion bash)\"", + "help": "Dump the shell completion script", "definition": { "arguments": { "shell": { diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.md b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md index 2fa9a220836fb..d4802c7470937 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md @@ -27,32 +27,7 @@ Dump the shell completion script * `completion [--debug] [--] []` -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 diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml b/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml index 801390ef5bd54..075aacc7b5399 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml @@ -53,32 +53,7 @@ completion [--debug] [--] [<shell>] Dump the shell completion script - The <info>completion</> command dumps the shell completion script required - to use shell autocompletion (currently only bash completion is supported). - - <comment>Static installation - -------------------</> - - Dump the script to a global completion file and restart your shell: - - <info>%%PHP_SELF%% completion bash | sudo tee /etc/bash_completion.d/%%COMMAND_NAME%%</> - - Or dump the script to a local file and source it: - - <info>%%PHP_SELF%% completion bash > 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:</> - <info>source /path/to/completion.sh</> - - <comment>Dynamic installation - --------------------</> - - Add this to the end of your shell configuration file (e.g. <info>"~/.bashrc"</>): - - <info>eval "$(%%PHP_SELF_FULL%% completion bash)"</> + Dump the shell completion script The shell type (e.g. "bash"), the value of the "$SHELL" env var will be used if this is not given diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md b/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md index 740ea5c202050..e7bc69c71019d 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md @@ -18,32 +18,7 @@ Dump the shell completion script * `completion [--debug] [--] []` -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 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