| 148 |
lars |
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 |
_sf_{{ COMMAND_NAME }}() {
|
|
|
9 |
# Use newline as only separator to allow space in completion values
|
|
|
10 |
IFS=$'\n'
|
|
|
11 |
local sf_cmd="${COMP_WORDS[0]}"
|
|
|
12 |
|
|
|
13 |
# for an alias, get the real script behind it
|
|
|
14 |
sf_cmd_type=$(type -t $sf_cmd)
|
|
|
15 |
if [[ $sf_cmd_type == "alias" ]]; then
|
|
|
16 |
sf_cmd=$(alias $sf_cmd | sed -E "s/alias $sf_cmd='(.*)'/\1/")
|
|
|
17 |
elif [[ $sf_cmd_type == "file" ]]; then
|
|
|
18 |
sf_cmd=$(type -p $sf_cmd)
|
|
|
19 |
fi
|
|
|
20 |
|
|
|
21 |
if [[ $sf_cmd_type != "function" && ! -x $sf_cmd ]]; then
|
|
|
22 |
return 1
|
|
|
23 |
fi
|
|
|
24 |
|
|
|
25 |
local cur prev words cword
|
|
|
26 |
_get_comp_words_by_ref -n := cur prev words cword
|
|
|
27 |
|
|
|
28 |
local completecmd=("$sf_cmd" "_complete" "--no-interaction" "-sbash" "-c$cword" "-a{{ VERSION }}")
|
|
|
29 |
for w in ${words[@]}; do
|
|
|
30 |
w=$(printf -- '%b' "$w")
|
|
|
31 |
# remove quotes from typed values
|
|
|
32 |
quote="${w:0:1}"
|
|
|
33 |
if [ "$quote" == \' ]; then
|
|
|
34 |
w="${w%\'}"
|
|
|
35 |
w="${w#\'}"
|
|
|
36 |
elif [ "$quote" == \" ]; then
|
|
|
37 |
w="${w%\"}"
|
|
|
38 |
w="${w#\"}"
|
|
|
39 |
fi
|
|
|
40 |
# empty values are ignored
|
|
|
41 |
if [ ! -z "$w" ]; then
|
|
|
42 |
completecmd+=("-i$w")
|
|
|
43 |
fi
|
|
|
44 |
done
|
|
|
45 |
|
|
|
46 |
local sfcomplete
|
|
|
47 |
if sfcomplete=$(${completecmd[@]} 2>&1); then
|
|
|
48 |
local quote suggestions
|
|
|
49 |
quote=${cur:0:1}
|
|
|
50 |
|
|
|
51 |
# Use single quotes by default if suggestions contains backslash (FQCN)
|
|
|
52 |
if [ "$quote" == '' ] && [[ "$sfcomplete" =~ \\ ]]; then
|
|
|
53 |
quote=\'
|
|
|
54 |
fi
|
|
|
55 |
|
|
|
56 |
if [ "$quote" == \' ]; then
|
|
|
57 |
# single quotes: no additional escaping (does not accept ' in values)
|
|
|
58 |
suggestions=$(for s in $sfcomplete; do printf $'%q%q%q\n' "$quote" "$s" "$quote"; done)
|
|
|
59 |
elif [ "$quote" == \" ]; then
|
|
|
60 |
# double quotes: double escaping for \ $ ` "
|
|
|
61 |
suggestions=$(for s in $sfcomplete; do
|
|
|
62 |
s=${s//\\/\\\\}
|
|
|
63 |
s=${s//\$/\\\$}
|
|
|
64 |
s=${s//\`/\\\`}
|
|
|
65 |
s=${s//\"/\\\"}
|
|
|
66 |
printf $'%q%q%q\n' "$quote" "$s" "$quote";
|
|
|
67 |
done)
|
|
|
68 |
else
|
|
|
69 |
# no quotes: double escaping
|
|
|
70 |
suggestions=$(for s in $sfcomplete; do printf $'%q\n' $(printf '%q' "$s"); done)
|
|
|
71 |
fi
|
|
|
72 |
COMPREPLY=($(IFS=$'\n' compgen -W "$suggestions" -- $(printf -- "%q" "$cur")))
|
|
|
73 |
__ltrim_colon_completions "$cur"
|
|
|
74 |
else
|
|
|
75 |
if [[ "$sfcomplete" != *"Command \"_complete\" is not defined."* ]]; then
|
|
|
76 |
>&2 echo
|
|
|
77 |
>&2 echo $sfcomplete
|
|
|
78 |
fi
|
|
|
79 |
|
|
|
80 |
return 1
|
|
|
81 |
fi
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
complete -F _sf_{{ COMMAND_NAME }} {{ COMMAND_NAME }}
|