From 96ea5e32b442ff2406f1d7268cccdd73baf313ea Mon Sep 17 00:00:00 2001 From: dana Date: Tue, 31 Jul 2018 20:46:09 -0500 Subject: 43207: Improve _bind_addresses, _php Minor change from the patch as posted to the ML: _php now calls _bind_addresses with -K, since it can't actually listen on a link-local address. --- Completion/Unix/Command/_php | 234 +++++++++++++++++++++++++++++++------------ 1 file changed, 170 insertions(+), 64 deletions(-) (limited to 'Completion/Unix/Command/_php') diff --git a/Completion/Unix/Command/_php b/Completion/Unix/Command/_php index d03f3395e..c4c4ab3e2 100644 --- a/Completion/Unix/Command/_php +++ b/Completion/Unix/Command/_php @@ -1,71 +1,177 @@ -#compdef php +#compdef php -P php[0-9.-] -# PHP 5.0.4 (cli) -# PHP 4.3.11 (cli) +# Notes: +# - We make no distinction between internal and user functions +# - We don't complete CGI options, which are rarely used interactively +# - Exclusivity on some of the miscellaneous options isn't very accurate +# - @todo Arguments to an -f script aren't completed accurately -- we need to +# massage words/CURRENT so that the -f arg becomes words[1], but if we just +# leave it at that the output will break if the script has any options of its +# own. We would want to complete script options only following `--`, as in +# `php -f /bin/foo -- -` -local curcontext="$curcontext" line state expl -typeset -A opt_args +# Complete PHP class names +(( $+functions[_php_classes] )) || +_php_classes() { + local cmd + local -a tmp -local -a args -local exclusions php_suffix + cmd='foreach ( get_declared_classes() as $c ) { echo "$c\n"; }' + tmp=( ${(f)"$( _call_program classes $words[1] -r ${(q)cmd} )"} ) -zstyle -s ":completion:${curcontext}:" suffixes php_suffix '|' || php_suffix='php|phar' -local php_files=":PHP file:_files -g '*.($php_suffix)(-.)'" + _wanted -x classes expl 'PHP class' compadd -a "$@" - tmp +} + +# Complete PHP extensions/module names; use --zend for Zend extensions only +(( $+functions[_php_extensions] )) || +_php_extensions() { + local idx + local -a expl zend tmp + + zparseopts -a zend -D -E -- -zend + + # `php -m` lists all extensions under two sections called '[PHP Modules]' and + # '[Zend Modules]'. An extension can (but won't necessarily) exist under both + # of these at the same time + tmp=( ${(f)"$( _call_program extensions $words[1] -m )"} ) + idx=${tmp[(i)\[Zend Modules\]]} + + # Get only Zend extensions (for --rz) + if (( $#zend )); then + tmp=( ${(@)tmp[(idx+1),-1]} ) + # Get PHP extensions (for everything else) + else + tmp=( ${(@)tmp[2,(idx-1)]} ) + fi + + _wanted -x extensions expl 'PHP extension' compadd -a "$@" - tmp +} + +# Complete PHP function names +(( $+functions[_php_functions] )) || +_php_functions() { + local cmd + local -a expl tmp + + cmd=' + foreach ( get_defined_functions() as $a ) { + foreach ( $a as $f ) { + echo "$f\n"; + } + } + ' + tmp=( ${(f)"$( _call_program functions $words[1] -r ${(q)cmd} )"} ) + + _wanted -x functions expl 'PHP function' compadd -a "$@" - tmp +} + +_php() { + local curcontext=$curcontext php_suffix php_files ret=1 + local -a context expl line state state_descr args + local -A opt_args + + zstyle -s ":completion:${curcontext}:" suffixes php_suffix '|' || + php_suffix='php|php5|phar' + + php_files=":PHP file:_files -g '*.($php_suffix)(#q-.)'" -if _pick_variant php5=PHP\ 5 php4 --version; then - exclusions="-B --process-begin -R --process-code -F --process-file -E --process-end" args=( - '(-B --process-begin -f --file -r --run 1)'{-B,--process-begin}'[run specified PHP code before processing input lines]:PHP code:' - '(-R --process-code -F --process-file -f --file -r --run 1)'{-R,--process-code}'[run specified PHP code for every input line]:PHP code:' - '(-F --process-file -R --process-code -f --file -r --run 1)'{-F,--process-file}'[parse and execute specified file for every input line]'$php_files - '(-E --process-end -f --file -r --run 1)'{-E,--process-end}'[run specified PHP code af