karma-completion.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. ###-begin-karma-completion-###
  2. #
  3. # karma command completion script
  4. # This is stolen from NPM. Thanks @isaac!
  5. #
  6. # Installation: karma completion >> ~/.bashrc (or ~/.zshrc)
  7. # Or, maybe: karma completion > /usr/local/etc/bash_completion.d/karma
  8. #
  9. if type complete &>/dev/null; then
  10. __karma_completion () {
  11. local si="$IFS"
  12. IFS=$'\n' COMPREPLY=($(COMP_CWORD="$COMP_CWORD" \
  13. COMP_LINE="$COMP_LINE" \
  14. COMP_POINT="$COMP_POINT" \
  15. karma completion -- "${COMP_WORDS[@]}" \
  16. 2>/dev/null)) || return $?
  17. IFS="$si"
  18. }
  19. complete -F __karma_completion karma
  20. elif type compdef &>/dev/null; then
  21. __karma_completion() {
  22. si=$IFS
  23. compadd -- $(COMP_CWORD=$((CURRENT-1)) \
  24. COMP_LINE=$BUFFER \
  25. COMP_POINT=0 \
  26. karma completion -- "${words[@]}" \
  27. 2>/dev/null)
  28. IFS=$si
  29. }
  30. compdef __karma_completion karma
  31. elif type compctl &>/dev/null; then
  32. __karma_completion () {
  33. local cword line point words si
  34. read -Ac words
  35. read -cn cword
  36. let cword-=1
  37. read -l line
  38. read -ln point
  39. si="$IFS"
  40. IFS=$'\n' reply=($(COMP_CWORD="$cword" \
  41. COMP_LINE="$line" \
  42. COMP_POINT="$point" \
  43. karma completion -- "${words[@]}" \
  44. 2>/dev/null)) || return $?
  45. IFS="$si"
  46. }
  47. compctl -K __karma_completion karma
  48. fi
  49. ###-end-karma-completion-###