Skip to content

Commit d90a1f7

Browse files
committed
Issue 43602 : Add fish completion
1 parent 540ee0a commit d90a1f7

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Console\Completion\CompletionInput;
1515
use Symfony\Component\Console\Completion\CompletionSuggestions;
1616
use Symfony\Component\Console\Completion\Output\BashCompletionOutput;
17+
use Symfony\Component\Console\Completion\Output\FishCompletionOutput;
1718
use Symfony\Component\Console\Exception\CommandNotFoundException;
1819
use Symfony\Component\Console\Exception\ExceptionInterface;
1920
use Symfony\Component\Console\Input\InputInterface;
@@ -32,6 +33,7 @@ final class CompleteCommand extends Command
3233

3334
private static $completionOutputs = [
3435
'bash' => BashCompletionOutput::class,
36+
'fish' => FishCompletionOutput::class,
3537
];
3638

3739
private $isDebug = false;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Console\Completion\Output;
13+
14+
use Symfony\Component\Console\Completion\CompletionSuggestions;
15+
use Symfony\Component\Console\Output\OutputInterface;
16+
17+
/**
18+
* @author Guillaume Aveline <guillaume.aveline@pm.me>
19+
*/
20+
class FishCompletionOutput implements CompletionOutputInterface
21+
{
22+
public function write(CompletionSuggestions $suggestions, OutputInterface $output): void
23+
{
24+
$options = [];
25+
foreach ($suggestions->getOptionSuggestions() as $option) {
26+
$options[] = '--'.$option->getName();
27+
}
28+
$output->write(implode(\PHP_EOL, $options));
29+
30+
$output->writeln(implode(\PHP_EOL, $suggestions->getValueSuggestions()));
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This file is part of the Symfony package.
2+
#
3+
# (c) Fabien Potencier <fabien@symfony.com>
4+
#
5+
# For the full copyright and license information, please view
6+
# https://symfony.com/doc/current/contributing/code/license.html
7+
8+
function _sf_{{ COMMAND_NAME }}
9+
set sf_cmd (string split ' ' (commandline))
10+
set c (math (count $sf_cmd) - 1)
11+
12+
set completecmd "$sf_cmd[1]" "_complete" "-sfish" "-S5.4.0-DEV"
13+
14+
for i in $sf_cmd
15+
if [ $i != "" ]
16+
set completecmd $completecmd "-i '$i'"
17+
end
18+
end
19+
20+
set completecmd $completecmd "-c$c"
21+
22+
set sfcomplete ($completecmd)
23+
24+
for i in $sfcomplete
25+
echo $i
26+
end
27+
end
28+
29+
complete -c '{{ COMMAND_NAME }}' -a '(_sf_{{ COMMAND_NAME }})' -f

0 commit comments

Comments
 (0)