|
| 1 | +# ------------------------------------------------------------------------------ |
| 2 | +# FILE: phpcli.plugin.zsh |
| 3 | +# DESCRIPTION: oh-my-zsh phpcli plugin file. |
| 4 | +# AUTHOR: Jitendra Adhikari ([email protected]) |
| 5 | +# VERSION: 0.0.1 |
| 6 | +# LICENSE: MIT |
| 7 | +# ------------------------------------------------------------------------------ |
| 8 | +# Specifically tuned to support autocompletion for apps build with adhocore/cli! |
| 9 | +# Check https://github.com/adhocore/php-cli#autocompletion |
| 10 | +# ------------------------------------------------------------------------------ |
| 11 | + |
| 12 | +# PHPCli command completion |
| 13 | +_phpcli_command_list () { |
| 14 | + command $1 --help 2>/dev/null | sed "1,/Commands/d" | grep -v Run | awk '/ [a-z]+ / { print $2 }' |
| 15 | +} |
| 16 | + |
| 17 | +# PHPCli option completion |
| 18 | +_phpcli_option_list () { |
| 19 | + command $1 $2 --help 2>/dev/null | sed '1,/Options/d' | gawk 'match($0, / .*(--[a-z-]+)(\.\.\.)?. /, o) { print o[1] }' |
| 20 | +} |
| 21 | + |
| 22 | +# PHPCli compdef handler |
| 23 | +_phpcli () { |
| 24 | + local curcontext="$curcontext" state line cmd subcmd |
| 25 | + typeset -A opt_args |
| 26 | + _arguments \ |
| 27 | + '1: :->cmd'\ |
| 28 | + '*: :->opts' |
| 29 | + |
| 30 | + cmd=`echo $curcontext | gawk 'match($0, /\:([_a-z-]+)\:$/, c) { print c[1] }'` |
| 31 | + subcmd=`echo $line | awk '{print $1}'` |
| 32 | + |
| 33 | + case $state in |
| 34 | + cmd) compadd $(_phpcli_command_list $cmd) ;; |
| 35 | + opts) compadd $(_phpcli_option_list $cmd $subcmd) ;; |
| 36 | + esac |
| 37 | +} |
| 38 | + |
| 39 | +# |
| 40 | +# Register commands for autocompletion below: |
| 41 | +# |
| 42 | +# format: compdef _phpcli <cmd> |
| 43 | +# example: compdef _phpcli phint |
| 44 | +# |
0 commit comments