1 # Copyright (C) 2007 Andre Noll <maan@tuebingen.mpg.de>
3 # Licensed under the GPL v2. For licencing details see COPYING.
7 local prg="$1" # the program to execute
8 local cur=${COMP_WORDS[$COMP_CWORD]}
9 local line="$COMP_LINE" OLD_IFS="$IFS"
12 # This extracts short and long options from the help output
14 if ($1 ~ "-[a-zA-Z]," && $2 ~ "--[a-zA-Z]") {
15 print substr($1, 0, 2);
18 } else if ($1 ~ "--[a-zA-Z]") {
24 if [[ "$cur" == -* ]]; then # option
25 # Depending on whether '--' is one of the previous words we
26 # complete either on local options, i.e. those of the program
27 # to execute, or call the program to print possible completions
30 for ((i=0; i < $COMP_CWORD; i++)); do
31 [[ "${COMP_WORDS[$i]}" != '--' ]] && continue
35 if [[ "$local_opts" == "true" ]]; then
36 result="-- $($prg --help | awk "$script")"
37 COMPREPLY=($(compgen -W "$result" -- $cur))
41 # We need to call the program with --complete to get the possible
42 # completions. Before that, all local options must be discarded.
46 ((n > 0)) && ! [[ "$word" == -* ]] && break
47 line="${line##*( )}" # remove leading whitespace
48 line="${line##+([^ ])}"
51 [[ "$word" == '--' ]] && break
54 s=$((${#COMP_LINE} - ${#line})) # how many characters have been cut
55 if (($COMP_POINT > $s)); then
56 COMP_POINT=$(($COMP_POINT - $s))
61 #echo "line: $COMP_LINE, point: $COMP_POINT"
62 export COMP_LINE COMP_POINT
63 result=($($prg --complete))
65 # the last line of the output contains the options for compopt,
66 # prefixed with '-o='.
68 (($n == 0)) && return # oops, $prg did not write any output
78 filenames) compopt -o filenames;;
79 nospace) compopt -o nospace;;
83 COMPREPLY=(${result[@]})
88 _para_complete para_audioc
90 complete -F _para_audioc para_audioc
94 _para_complete para_client
96 complete -o default -o nospace -F _para_client para_client
97 complete -o default -o nospace -F _para_client para