Diff
1diff --git a/plugins/symfony6/README.md b/plugins/symfony6/README.md
2new file mode 100644
3index 0000000000000000000000000000000000000000..54611bcee8f766a501a571bc32b8f1ae19003659
4--- /dev/null
5+++ b/plugins/symfony6/README.md
6@@ -0,0 +1,9 @@
7+# Symfony
8+
9+This plugin provides native completion for [Symfony](https://symfony.com/), but requires at least Symfony 6.2.
10+
11+To use it add `symfony6` to the plugins array in your zshrc file.
12+
13+```bash
14+plugins=(... symfony6)
15+```
16diff --git a/plugins/symfony6/symfony6.plugin.zsh b/plugins/symfony6/symfony6.plugin.zsh
17new file mode 100644
18index 0000000000000000000000000000000000000000..ed7dbe60ec2cdad0a65bfa3efb3542d94bb47a99
19--- /dev/null
20+++ b/plugins/symfony6/symfony6.plugin.zsh
21@@ -0,0 +1,82 @@
22+#compdef console
23+
24+# This file is part of the Symfony package.
25+#
26+# (c) Fabien Potencier <fabien@symfony.com>
27+#
28+# For the full copyright and license information, please view
29+# https://symfony.com/doc/current/contributing/code/license.html
30+
31+#
32+# zsh completions for console
33+#
34+# References:
35+# - https://github.com/spf13/cobra/blob/master/zsh_completions.go
36+# - https://github.com/symfony/symfony/blob/5.4/src/Symfony/Component/Console/Resources/completion.bash
37+#
38+_sf_console() {
39+ local lastParam flagPrefix requestComp out comp
40+ local -a completions
41+
42+ # The user could have moved the cursor backwards on the command-line.
43+ # We need to trigger completion from the $CURRENT location, so we need
44+ # to truncate the command-line ($words) up to the $CURRENT location.
45+ # (We cannot use $CURSOR as its value does not work when a command is an alias.)
46+ words=("${=words[1,CURRENT]}") lastParam=${words[-1]}
47+
48+ # For zsh, when completing a flag with an = (e.g., console -n=<TAB>)
49+ # completions must be prefixed with the flag
50+ setopt local_options BASH_REMATCH
51+ if [[ "${lastParam}" =~ '-.*=' ]]; then
52+ # We are dealing with a flag with an =
53+ flagPrefix="-P ${BASH_REMATCH}"
54+ fi
55+
56+ # Prepare the command to obtain completions
57+ requestComp="${words[0]} ${words[1]} _complete --no-interaction -szsh -a1 -c$((CURRENT-1))" i=""
58+ for w in ${words[@]}; do
59+ w=$(printf -- '%b' "$w")
60+ # remove quotes from typed values
61+ quote="${w:0:1}"
62+ if [ "$quote" = \' ]; then
63+ w="${w%\'}"
64+ w="${w#\'}"
65+ elif [ "$quote" = \" ]; then
66+ w="${w%\"}"
67+ w="${w#\"}"
68+ fi
69+ # empty values are ignored
70+ if [ ! -z "$w" ]; then
71+ i="${i}-i${w} "
72+ fi
73+ done
74+
75+ # Ensure at least 1 input
76+ if [ "${i}" = "" ]; then
77+ requestComp="${requestComp} -i\" \""
78+ else
79+ requestComp="${requestComp} ${i}"
80+ fi
81+
82+ # Use eval to handle any environment variables and such
83+ out=$(eval ${requestComp} 2>/dev/null)
84+
85+ while IFS='\n' read -r comp; do
86+ if [ -n "$comp" ]; then
87+ # If requested, completions are returned with a description.
88+ # The description is preceded by a TAB character.
89+ # For zsh's _describe, we need to use a : instead of a TAB.
90+ # We first need to escape any : as part of the completion itself.
91+ comp=${comp//:/\\:}
92+ local tab=$(printf '\t')
93+ comp=${comp//$tab/:}
94+ completions+=${comp}
95+ fi
96+ done < <(printf "%s\n" "${out[@]}")
97+
98+ # Let inbuilt _describe handle completions
99+ eval _describe "completions" completions $flagPrefix
100+ return $?
101+}
102+
103+compdef _sf_console console