_watson
966 bytes
1#compdef watson
2
3_watson_completion() {
4 local -a completions
5 local -a completions_with_descriptions
6 local -a response
7 (( ! $+commands[watson] )) && return 1
8
9 response=("${(@f)$(env COMP_WORDS="${words[*]}" COMP_CWORD=$((CURRENT-1)) _WATSON_COMPLETE=zsh_complete watson)}")
10
11 for type key descr in ${response}; do
12 if [[ "$type" == "plain" ]]; then
13 if [[ "$descr" == "_" ]]; then
14 completions+=("$key")
15 else
16 completions_with_descriptions+=("$key":"$descr")
17 fi
18 elif [[ "$type" == "dir" ]]; then
19 _path_files -/
20 elif [[ "$type" == "file" ]]; then
21 _path_files -f
22 fi
23 done
24
25 if [ -n "$completions_with_descriptions" ]; then
26 _describe -V unsorted completions_with_descriptions -U
27 fi
28
29 if [ -n "$completions" ]; then
30 compadd -U -V unsorted -a completions
31 fi
32}
33
34compdef _watson_completion watson;