From 764e845cda1520d6ad2b92d525fb19d74c926b58 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 21 Apr 2023 19:34:39 +0200 Subject: [PATCH] Fix the usage of the zsh completion through the fpath discovery Zsh completion files registered through the fpath discovery mecanism have 2 requirements: - the file name must have a `_` prefix - the file must start with a `#compdef` comment describing the registration for that file. The file can then either execute the completion logic directly or call `compdef` to register a function for completion. Keeping the second approach allows to use the same generated script for the global use case than for a sourced configuration script. --- src/Symfony/Component/Console/Command/DumpCompletionCommand.php | 2 +- src/Symfony/Component/Console/Resources/completion.zsh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Command/DumpCompletionCommand.php b/src/Symfony/Component/Console/Command/DumpCompletionCommand.php index 6a322c92954a6..caf3bd15bfbc8 100644 --- a/src/Symfony/Component/Console/Command/DumpCompletionCommand.php +++ b/src/Symfony/Component/Console/Command/DumpCompletionCommand.php @@ -48,7 +48,7 @@ protected function configure() $shell = $this->guessShell(); [$rcFile, $completionFile] = match ($shell) { 'fish' => ['~/.config/fish/config.fish', "/etc/fish/completions/$commandName.fish"], - 'zsh' => ['~/.zshrc', '$fpath[1]/'.$commandName], + 'zsh' => ['~/.zshrc', '$fpath[1]/_'.$commandName], default => ['~/.bashrc', "/etc/bash_completion.d/$commandName"], }; diff --git a/src/Symfony/Component/Console/Resources/completion.zsh b/src/Symfony/Component/Console/Resources/completion.zsh index 97a9e88cd617c..ff76fe5fa981c 100644 --- a/src/Symfony/Component/Console/Resources/completion.zsh +++ b/src/Symfony/Component/Console/Resources/completion.zsh @@ -1,3 +1,5 @@ +#compdef {{ COMMAND_NAME }} + # This file is part of the Symfony package. # # (c) Fabien Potencier