_watson 966 B

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