1 # Copyright (C) 2007 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING.
4 local prg="$1" # the program to execute
5 local cur=${COMP_WORDS[$COMP_CWORD]}
6 local line="$COMP_LINE" OLD_IFS="$IFS"
9 # This extracts short and long options from the help output
11 if ($1 ~ "-[a-zA-Z]," && $2 ~ "--[a-zA-Z]") {
12 print substr($1, 0, 2);
15 } else if ($1 ~ "--[a-zA-Z]") {
21 if [[ "$cur" == -* ]]; then # option
22 # Depending on whether '--' is one of the previous words we
23 # complete either on local options, i.e. those of the program
24 # to execute, or call the program to print possible completions
27 for ((i=0; i < $COMP_CWORD; i++)); do
28 [[ "${COMP_WORDS[$i]}" != '--' ]] && continue
32 if [[ "$local_opts" == "true" ]]; then
33 result="-- $($prg --help | awk "$script")"
34 COMPREPLY=($(compgen -W "$result" -- $cur))
38 # We need to call the program with --complete to get the possible
39 # completions. Before that, all local options must be discarded.
43 ((n > 0)) && ! [[ "$word" == -* ]] && break
44 line="${line##*( )}" # remove leading whitespace
45 line="${line##+([^ ])}"
48 [[ "$word" == '--' ]] && break
51 s=$((${#COMP_LINE} - ${#line})) # how many characters have been cut
52 if (($COMP_POINT > $s)); then
53 COMP_POINT=$(($COMP_POINT - $s))
58 #echo "line: $COMP_LINE, point: $COMP_POINT"
59 export COMP_LINE COMP_POINT
60 result=($($prg --complete))
62 # the last line of the output contains the options for compopt,
63 # prefixed with '-o='.
65 (($n == 0)) && return # oops, $prg did not write any output
75 filenames) compopt -o filenames;;
76 nospace) compopt -o nospace;;
80 COMPREPLY=(${result[@]})
85 _para_complete para_audioc
87 complete -F _para_audioc para_audioc
91 _para_complete para_client
93 complete -o default -o nospace -F _para_client para_client
94 complete -o default -o nospace -F _para_client para