Revision 148 | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed
#compdef {{ COMMAND_NAME }}# This file is part of the Symfony package.## (c) Fabien Potencier <fabien@symfony.com>## For the full copyright and license information, please view# https://symfony.com/doc/current/contributing/code/license.html## zsh completions for {{ COMMAND_NAME }}## References:# - https://github.com/spf13/cobra/blob/master/zsh_completions.go# - https://github.com/symfony/symfony/blob/5.4/src/Symfony/Component/Console/Resources/completion.bash#_sf_{{ COMMAND_NAME }}() {local lastParam flagPrefix requestComp out complocal -a completions# The user could have moved the cursor backwards on the command-line.# We need to trigger completion from the $CURRENT location, so we need# to truncate the command-line ($words) up to the $CURRENT location.# (We cannot use $CURSOR as its value does not work when a command is an alias.)words=("${=words[1,CURRENT]}") lastParam=${words[-1]}# For zsh, when completing a flag with an = (e.g., {{ COMMAND_NAME }} -n=<TAB>)# completions must be prefixed with the flagsetopt local_options BASH_REMATCHif [[ "${lastParam}" =~ '-.*=' ]]; then# We are dealing with a flag with an =flagPrefix="-P ${BASH_REMATCH}"fi# Prepare the command to obtain completionsrequestComp="${words[0]} ${words[1]} _complete --no-interaction -szsh -a{{ VERSION }} -c$((CURRENT-1))" i=""for w in ${words[@]}; dow=$(printf -- '%b' "$w")# remove quotes from typed valuesquote="${w:0:1}"if [ "$quote" = \' ]; thenw="${w%\'}"w="${w#\'}"elif [ "$quote" = \" ]; thenw="${w%\"}"w="${w#\"}"fi# empty values are ignoredif [ ! -z "$w" ]; theni="${i}-i${w} "fidone# Ensure at least 1 inputif [ "${i}" = "" ]; thenrequestComp="${requestComp} -i\" \""elserequestComp="${requestComp} ${i}"fi# Use eval to handle any environment variables and suchout=$(eval ${requestComp} 2>/dev/null)while IFS='\n' read -r comp; doif [ -n "$comp" ]; then# If requested, completions are returned with a description.# The description is preceded by a TAB character.# For zsh's _describe, we need to use a : instead of a TAB.# We first need to escape any : as part of the completion itself.comp=${comp//:/\\:}local tab=$(printf '\t')comp=${comp//$tab/:}completions+=${comp}fidone < <(printf "%s\n" "${out[@]}")# Let inbuilt _describe handle completionseval _describe "completions" completions $flagPrefixreturn $?}compdef _sf_{{ COMMAND_NAME }} {{ COMMAND_NAME }}