Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DumpCompletionCommand.php

function DumpCompletionCommand::configure

Overrides Command::configure

File

vendor/symfony/console/Command/DumpCompletionCommand.php, line 32

Class

DumpCompletionCommand
Dumps the completion script for the current shell.

Namespace

Symfony\Component\Console\Command

Code

protected function configure() : void {
    $fullCommand = $_SERVER['PHP_SELF'];
    $commandName = basename($fullCommand);
    $fullCommand = @realpath($fullCommand) ?: $fullCommand;
    $shell = self::guessShell();
    [
        $rcFile,
        $completionFile,
    ] = match ($shell) {    'fish' => [
            '~/.config/fish/config.fish',
            "/etc/fish/completions/{$commandName}.fish",
        ],
        'zsh' => [
            '~/.zshrc',
            '$fpath[1]/_' . $commandName,
        ],
        default => [
            '~/.bashrc',
            "/etc/bash_completion.d/{$commandName}",
        ],
    
    };
    $supportedShells = implode(', ', $this->getSupportedShells());
    $this->setHelp(<<<EOH
The <info>%command.name%</> command dumps the shell completion script required
to use shell autocompletion (currently, {<span class="php-variable">$supportedShells</span>} completion are supported).

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

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

    <info>%command.full_name% {<span class="php-variable">$shell</span>} | sudo tee {<span class="php-variable">$completionFile</span>}</>

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

    <info>%command.full_name% {<span class="php-variable">$shell</span>} > 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 "{<span class="php-variable">$rcFile</span>}" file:</>
    <info>source /path/to/completion.sh</>

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

Add this to the end of your shell configuration file (e.g. <info>"{<span class="php-variable">$rcFile</span>}"</>):

    <info>eval "\$({<span class="php-variable">$fullCommand</span>} completion {<span class="php-variable">$shell</span>})"</>
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(...))
        ->addOption('debug', null, InputOption::VALUE_NONE, 'Tail the completion debug log');
}
RSS feed
Powered by Drupal