Skip to content

Commit 0d1b980

Browse files
wouterjnicolas-grekas
authored andcommitted
[Console] Fix fish completion script
1 parent fe63f83 commit 0d1b980

File tree

10 files changed

+23
-139
lines changed

10 files changed

+23
-139
lines changed

src/Symfony/Component/Console/Command/DumpCompletionCommand.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,34 +45,40 @@ protected function configure()
4545
$commandName = basename($fullCommand);
4646
$fullCommand = realpath($fullCommand) ?: $fullCommand;
4747

48+
$shell = $this->guessShell();
49+
[$rcFile, $completionFile] = match ($shell) {
50+
'fish' => ['~/.config/fish/config.fish', "/etc/fish/completions/$commandName.fish"],
51+
default => ['~/.bashrc', "/etc/bash_completion.d/$commandName"],
52+
};
53+
4854
$this
4955
->setHelp(<<<EOH
5056
The <info>%command.name%</> command dumps the shell completion script required
51-
to use shell autocompletion (currently only bash completion is supported).
57+
to use shell autocompletion (currently, bash and fish completion is supported).
5258
5359
<comment>Static installation
5460
-------------------</>
5561
5662
Dump the script to a global completion file and restart your shell:
5763
58-
<info>%command.full_name% bash | sudo tee /etc/bash_completion.d/${commandName}</>
64+
<info>%command.full_name% {$shell} | sudo tee {$completionFile}</>
5965
6066
Or dump the script to a local file and source it:
6167
62-
<info>%command.full_name% bash > completion.sh</>
68+
<info>%command.full_name% {$shell} > completion.sh</>
6369
6470
<comment># source the file whenever you use the project</>
6571
<info>source completion.sh</>
6672
67-
<comment># or add this line at the end of your "~/.bashrc" file:</>
73+
<comment># or add this line at the end of your "{$rcFile}" file:</>
6874
<info>source /path/to/completion.sh</>
6975
7076
<comment>Dynamic installation
7177
--------------------</>
7278
73-
Add this to the end of your shell configuration file (e.g. <info>"~/.bashrc"</>):
79+
Add this to the end of your shell configuration file (e.g. <info>"{$rcFile}"</>):
7480
75-
<info>eval "$(${fullCommand} completion bash)"</>
81+
<info>eval "$({$fullCommand} completion {$shell})"</>
7682
EOH
7783
)
7884
->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(...))

src/Symfony/Component/Console/Resources/completion.fish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
function _sf_{{ COMMAND_NAME }}
99
set sf_cmd (commandline -o)
10-
set c (math (count (commandline -oc))) - 1)
10+
set c (count (commandline -oc))
1111

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

src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public function testDescribeCommand(Command $command, $expectedDescription)
4848
/** @dataProvider getDescribeApplicationTestData */
4949
public function testDescribeApplication(Application $application, $expectedDescription)
5050
{
51+
// the "completion" command has dynamic help information depending on the shell
52+
$application->find('completion')->setHelp('');
53+
5154
$this->assertDescription($expectedDescription, $application);
5255
}
5356

src/Symfony/Component/Console/Tests/Fixtures/application_1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
"completion [--debug] [--] [<shell>]"
121121
],
122122
"description": "Dump the shell completion script",
123-
"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)\"</>",
123+
"help": "Dump the shell completion script",
124124
"definition": {
125125
"arguments": {
126126
"shell": {

src/Symfony/Component/Console/Tests/Fixtures/application_1.md

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,7 @@ Dump the shell completion script
1414

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

17-
The completion command dumps the shell completion script required
18-
to use shell autocompletion (currently only bash completion is supported).
19-
20-
Static installation
21-
-------------------
22-
23-
Dump the script to a global completion file and restart your shell:
24-
25-
%%PHP_SELF%% completion bash | sudo tee /etc/bash_completion.d/%%COMMAND_NAME%%
26-
27-
Or dump the script to a local file and source it:
28-
29-
%%PHP_SELF%% completion bash > completion.sh
30-
31-
# source the file whenever you use the project
32-
source completion.sh
33-
34-
# or add this line at the end of your "~/.bashrc" file:
35-
source /path/to/completion.sh
36-
37-
Dynamic installation
38-
--------------------
39-
40-
Add this to the end of your shell configuration file (e.g. "~/.bashrc"):
41-
42-
eval "$(%%PHP_SELF_FULL%% completion bash)"
17+
Dump the shell completion script
4318

4419
### Arguments
4520

src/Symfony/Component/Console/Tests/Fixtures/application_1.xml

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,32 +53,7 @@
5353
<usage>completion [--debug] [--] [&lt;shell&gt;]</usage>
5454
</usages>
5555
<description>Dump the shell completion script</description>
56-
<help>The &lt;info&gt;completion&lt;/&gt; command dumps the shell completion script required
57-
to use shell autocompletion (currently only bash completion is supported).
58-
59-
&lt;comment&gt;Static installation
60-
-------------------&lt;/&gt;
61-
62-
Dump the script to a global completion file and restart your shell:
63-
64-
&lt;info&gt;%%PHP_SELF%% completion bash | sudo tee /etc/bash_completion.d/%%COMMAND_NAME%%&lt;/&gt;
65-
66-
Or dump the script to a local file and source it:
67-
68-
&lt;info&gt;%%PHP_SELF%% completion bash &gt; completion.sh&lt;/&gt;
69-
70-
&lt;comment&gt;# source the file whenever you use the project&lt;/&gt;
71-
&lt;info&gt;source completion.sh&lt;/&gt;
72-
73-
&lt;comment&gt;# or add this line at the end of your "~/.bashrc" file:&lt;/&gt;
74-
&lt;info&gt;source /path/to/completion.sh&lt;/&gt;
75-
76-
&lt;comment&gt;Dynamic installation
77-
--------------------&lt;/&gt;
78-
79-
Add this to the end of your shell configuration file (e.g. &lt;info&gt;"~/.bashrc"&lt;/&gt;):
80-
81-
&lt;info&gt;eval "$(%%PHP_SELF_FULL%% completion bash)"&lt;/&gt;</help>
56+
<help>Dump the shell completion script</help>
8257
<arguments>
8358
<argument name="shell" is_required="0" is_array="0">
8459
<description>The shell type (e.g. "bash"), the value of the "$SHELL" env var will be used if this is not given</description>

src/Symfony/Component/Console/Tests/Fixtures/application_2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
"completion [--debug] [--] [<shell>]"
125125
],
126126
"description": "Dump the shell completion script",
127-
"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)\"</>",
127+
"help": "Dump the shell completion script",
128128
"definition": {
129129
"arguments": {
130130
"shell": {

src/Symfony/Component/Console/Tests/Fixtures/application_2.md

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,7 @@ Dump the shell completion script
2727

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

30-
The completion command dumps the shell completion script required
31-
to use shell autocompletion (currently only bash completion is supported).
32-
33-
Static installation
34-
-------------------
35-
36-
Dump the script to a global completion file and restart your shell:
37-
38-
%%PHP_SELF%% completion bash | sudo tee /etc/bash_completion.d/%%COMMAND_NAME%%
39-
40-
Or dump the script to a local file and source it:
41-
42-
%%PHP_SELF%% completion bash > completion.sh
43-
44-
# source the file whenever you use the project
45-
source completion.sh
46-
47-
# or add this line at the end of your "~/.bashrc" file:
48-
source /path/to/completion.sh
49-
50-
Dynamic installation
51-
--------------------
52-
53-
Add this to the end of your shell configuration file (e.g. "~/.bashrc"):
54-
55-
eval "$(%%PHP_SELF_FULL%% completion bash)"
30+
Dump the shell completion script
5631

5732
### Arguments
5833

src/Symfony/Component/Console/Tests/Fixtures/application_2.xml

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,32 +53,7 @@
5353
<usage>completion [--debug] [--] [&lt;shell&gt;]</usage>
5454
</usages>
5555
<description>Dump the shell completion script</description>
56-
<help>The &lt;info&gt;completion&lt;/&gt; command dumps the shell completion script required
57-
to use shell autocompletion (currently only bash completion is supported).
58-
59-
&lt;comment&gt;Static installation
60-
-------------------&lt;/&gt;
61-
62-
Dump the script to a global completion file and restart your shell:
63-
64-
&lt;info&gt;%%PHP_SELF%% completion bash | sudo tee /etc/bash_completion.d/%%COMMAND_NAME%%&lt;/&gt;
65-
66-
Or dump the script to a local file and source it:
67-
68-
&lt;info&gt;%%PHP_SELF%% completion bash &gt; completion.sh&lt;/&gt;
69-
70-
&lt;comment&gt;# source the file whenever you use the project&lt;/&gt;
71-
&lt;info&gt;source completion.sh&lt;/&gt;
72-
73-
&lt;comment&gt;# or add this line at the end of your "~/.bashrc" file:&lt;/&gt;
74-
&lt;info&gt;source /path/to/completion.sh&lt;/&gt;
75-
76-
&lt;comment&gt;Dynamic installation
77-
--------------------&lt;/&gt;
78-
79-
Add this to the end of your shell configuration file (e.g. &lt;info&gt;"~/.bashrc"&lt;/&gt;):
80-
81-
&lt;info&gt;eval "$(%%PHP_SELF_FULL%% completion bash)"&lt;/&gt;</help>
56+
<help>Dump the shell completion script</help>
8257
<arguments>
8358
<argument name="shell" is_required="0" is_array="0">
8459
<description>The shell type (e.g. "bash"), the value of the "$SHELL" env var will be used if this is not given</description>

src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,7 @@ Dump the shell completion script
1818

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

21-
The completion command dumps the shell completion script required
22-
to use shell autocompletion (currently only bash completion is supported).
23-
24-
Static installation
25-
-------------------
26-
27-
Dump the script to a global completion file and restart your shell:
28-
29-
%%PHP_SELF%% completion bash | sudo tee /etc/bash_completion.d/%%COMMAND_NAME%%
30-
31-
Or dump the script to a local file and source it:
32-
33-
%%PHP_SELF%% completion bash > completion.sh
34-
35-
# source the file whenever you use the project
36-
source completion.sh
37-
38-
# or add this line at the end of your "~/.bashrc" file:
39-
source /path/to/completion.sh
40-
41-
Dynamic installation
42-
--------------------
43-
44-
Add this to the end of your shell configuration file (e.g. "~/.bashrc"):
45-
46-
eval "$(%%PHP_SELF_FULL%% completion bash)"
21+
Dump the shell completion script
4722

4823
### Arguments
4924

0 commit comments

Comments
 (0)