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 if [[ "$COMP_WORDBREAKS" != ' ' ]]; then
11 return 124 # try again with proper value
13 # This extracts short and long options from the help output
15 if ($1 ~ "-[a-zA-Z]," && $2 ~ "--[a-zA-Z]") {
16 print substr($1, 0, 2);
19 } else if ($1 ~ "--[a-zA-Z]") {
25 if [[ "$cur" == -* ]]; then # option
26 # Depending on whether '--' is one of the previous words we
27 # complete either on local options, i.e. those of the program
28 # to execute, or call the program to print possible completions
31 for ((i=0; i < $COMP_CWORD; i++)); do
32 [[ "${COMP_WORDS[$i]}" != '--' ]] && continue
36 if [[ "$local_opts" == "true" ]]; then
37 result="-- $($prg --help | awk "$script")"
38 COMPREPLY=($(compgen -W "$result" -- $cur))
42 # We need to call the program with --complete to get the possible
43 # completions. Before that, all local options must be discarded.
47 ((n > 0)) && ! [[ "$word" == -* ]] && break
48 line="${line##*( )}" # remove leading whitespace
49 line="${line##+([^ ])}"
52 [[ "$word" == '--' ]] && break
55 s=$((${#COMP_LINE} - ${#line})) # how many characters have been cut
56 if (($COMP_POINT > $s)); then
57 COMP_POINT=$(($COMP_POINT - $s))
62 #echo "line: $COMP_LINE, point: $COMP_POINT"
63 export COMP_LINE COMP_POINT
64 result=($($prg --complete))
66 # the last line of the output contains the options for compopt,
67 # prefixed with '-o='.
69 (($n == 0)) && return # oops, $prg did not write any output
79 filenames) compopt -o filenames;;
80 nospace) compopt -o nospace;;
84 COMPREPLY=(${result[@]})
89 _para_complete para_audioc
91 complete -F _para_audioc para_audioc
95 _para_complete para_client
97 complete -o default -o nospace -F _para_client para_client
98 complete -o default -o nospace -F _para_client para