test.sh 1.5 KB

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