zsh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/zsh
  2. # grunt-cli
  3. # http://gruntjs.com/
  4. #
  5. # Copyright (c) 2016 Tyler Kellen, contributors
  6. # Licensed under the MIT license.
  7. # https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
  8. # Usage:
  9. #
  10. # To enable zsh <tab> completion for grunt, add the following line (minus the
  11. # leading #, which is the zsh comment character) to your ~/.zshrc file:
  12. #
  13. # eval "$(grunt --completion=zsh)"
  14. # Enable zsh autocompletion.
  15. function _grunt_completion() {
  16. local completions
  17. # The currently-being-completed word.
  18. local cur="${words[@]}"
  19. # The current grunt version, available tasks, options, etc.
  20. local gruntinfo="$(grunt --version --verbose 2>/dev/null)"
  21. # Options and tasks.
  22. local opts="$(echo "$gruntinfo" | awk '/Available options: / {$1=$2=""; print $0}')"
  23. local compls="$(echo "$gruntinfo" | awk '/Available tasks: / {$1=$2=""; print $0}')"
  24. # Only add -- or - options if the user has started typing -
  25. [[ "$cur" == -* ]] && compls="$compls $opts"
  26. # Trim whitespace.
  27. compls=$(echo "$compls" | sed -e 's/^ *//g' -e 's/ *$//g')
  28. # Turn compls into an array to of completions.
  29. completions=(${=compls})
  30. # Tell complete what stuff to show.
  31. compadd -- $completions
  32. }
  33. compdef _grunt_completion grunt