diff options
Diffstat (limited to 'completions/function')
-rw-r--r-- | completions/function | 36 |
1 files changed, 8 insertions, 28 deletions
diff --git a/completions/function b/completions/function index 6ae5271..218f0cf 100644 --- a/completions/function +++ b/completions/function @@ -1,37 +1,17 @@ # bash shell function completion -*- shell-script -*- -_function() +_comp_cmd_function() { - local cur prev words cword - _init_completion || return + local cur prev words cword comp_args + _comp_initialize -- "$@" || return - if [[ $1 == @(declare|typeset) ]]; then - if [[ $cur == [-+]* ]]; then - local opts - opts=($(_parse_usage "$1")) - # Most options also have a '+' form. We'll exclude the ones that don't with compgen. - opts+=(${opts[*]/-/+}) - COMPREPLY=($(compgen -W "${opts[*]}" -X '+[Ffgp]' -- "$cur")) - else - local i=1 - while [[ ${words[i]} == [-+]* ]]; do - if [[ ${words[i]} == -*[fF]* ]]; then - COMPREPLY=($(compgen -A function -- "$cur")) - return - fi - ((i++)) - done - if ((i > 1)); then - # There was at least one option and it was not one that limited operations to functions - COMPREPLY=($(compgen -A variable -- "$cur")) - fi - fi - elif ((cword == 1)); then - COMPREPLY=($(compgen -A function -- "$cur")) + if ((cword == 1)); then + _comp_compgen -- -A function else - COMPREPLY=("() $(type -- ${words[1]} | command sed -e 1,2d)") + local funcdef=$(type -- "${words[1]}" 2>/dev/null | command sed -e 1,2d) + COMPREPLY=("()${funcdef:+ $funcdef}") fi } && - complete -F _function function declare typeset + complete -F _comp_cmd_function function # ex: filetype=sh |