|
|
|
@ -12,21 +12,47 @@
|
|
|
|
|
|
|
|
|
|
_yii() |
|
|
|
|
{ |
|
|
|
|
local cur opts yii |
|
|
|
|
local cur opts yii command |
|
|
|
|
COMPREPLY=() |
|
|
|
|
cur="${COMP_WORDS[COMP_CWORD]}" |
|
|
|
|
yii="${COMP_WORDS[0]}" |
|
|
|
|
|
|
|
|
|
# only complete first argument |
|
|
|
|
if [[ COMP_CWORD -eq 1 ]] ; then |
|
|
|
|
# fetch available commands from ./yii help/list command |
|
|
|
|
opts=$($yii help/list) |
|
|
|
|
# generate completion suggestions |
|
|
|
|
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) |
|
|
|
|
return 0 |
|
|
|
|
fi |
|
|
|
|
# exit if ./yii does not exist |
|
|
|
|
test -f $yii || return 0 |
|
|
|
|
|
|
|
|
|
# lookup for command |
|
|
|
|
for word in ${COMP_WORDS[@]:1}; do |
|
|
|
|
if [[ $word != -* ]]; then |
|
|
|
|
command=$word |
|
|
|
|
break |
|
|
|
|
fi |
|
|
|
|
done |
|
|
|
|
|
|
|
|
|
[[ $cur == $command ]] && state="command" |
|
|
|
|
[[ $cur != $command ]] && state="option" |
|
|
|
|
[[ $cur = *=* ]] && state="value" |
|
|
|
|
|
|
|
|
|
case $state in |
|
|
|
|
command) |
|
|
|
|
# complete command/route if not given |
|
|
|
|
# fetch available commands from ./yii help/list command |
|
|
|
|
opts=$($yii help/list 2> /dev/null) |
|
|
|
|
;; |
|
|
|
|
option) |
|
|
|
|
# fetch available options from ./yii help/list-action-options command |
|
|
|
|
opts=$($yii help/list-action-options $command 2> /dev/null | grep -o '^--[a-zA-Z0-9]*') |
|
|
|
|
;; |
|
|
|
|
value) |
|
|
|
|
# TODO allow normal file completion after an option, e.g. --migrationPath=... |
|
|
|
|
;; |
|
|
|
|
esac |
|
|
|
|
|
|
|
|
|
# generate completion suggestions |
|
|
|
|
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) |
|
|
|
|
return 0 |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# register completion for the ./yii command |
|
|
|
|
# you may adjust this line if your command file is named differently |
|
|
|
|
complete -F _yii ./yii |
|
|
|
|
complete -F _yii ./yii yii |
|
|
|
|