scripts/dav-bash-completion.bash

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

mercurial