1 dav_completion_build_args() {
2 local word
3 for i in "${!COMP_WORDS[@]}"; do
4 word="${COMP_WORDS[$i]}"
5 if [[ "$word" =~ ^\'|^\" ]]; then
6 printf "%s\n" "$word"
7 else
8 echo "$word" | xargs printf "%s"
9 printf "\n"
10 fi
11 done
12 }
13
14 dav_completion() {
15 local cmd
16 local out
17 local cmd_res
18
19 cmd="${COMP_WORDS[0]} complete $COMP_CWORD"
20 out=$(dav_completion_build_args | $cmd 2> /dev/null)
21 cmd_res=$?
22
23 if [[ $cmd_res -eq 10 ]]; then
24 compopt -o nospace
25 fi
26
27
28 if [[ $cmd_res -eq 12 ]]; then
29 compopt -o default
30 COMPREPLY=()
31 else
32 IFS=$'\n' declare -ga 'COMPREPLY=($out)'
33 fi
34 }
35
36 complete -F dav_completion dav
37
38