bash 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  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 bash <tab> completion for grunt, add the following line (minus the
  11. # leading #, which is the bash comment character) to your ~/.bashrc file:
  12. #
  13. # eval "$(grunt --completion=bash)"
  14. # Search the current directory and all parent directories for a gruntfile.
  15. function _grunt_gruntfile() {
  16. local curpath="$PWD"
  17. while [[ "$curpath" ]]; do
  18. for gruntfile in "$curpath/"{G,g}runtfile.{js,coffee}; do
  19. if [[ -e "$gruntfile" ]]; then
  20. echo "$gruntfile"
  21. return
  22. fi
  23. done
  24. curpath="${curpath%/*}"
  25. done
  26. return 1
  27. }
  28. # Enable bash autocompletion.
  29. function _grunt_completions() {
  30. # The currently-being-completed word.
  31. local cur="${COMP_WORDS[COMP_CWORD]}"
  32. # The current gruntfile, if it exists.
  33. local gruntfile="$(_grunt_gruntfile)"
  34. # The current grunt version, available tasks, options, etc.
  35. local gruntinfo="$(grunt --version --verbose 2>/dev/null)"
  36. # Options and tasks.
  37. local opts="$(echo "$gruntinfo" | awk '/Available options: / {$1=$2=""; print $0}')"
  38. local compls="$(echo "$gruntinfo" | awk '/Available tasks: / {$1=$2=""; print $0}')"
  39. # Only add -- or - options if the user has started typing -
  40. [[ "$cur" == -* ]] && compls="$compls $opts"
  41. # Tell complete what stuff to show.
  42. COMPREPLY=($(compgen -W "$compls" -- "$cur"))
  43. }
  44. complete -o default -F _grunt_completions grunt