grails.plugin.zsh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. _enumerateGrailsScripts() {
  2. # Default directories
  3. directories=($GRAILS_HOME/scripts ~/.grails/scripts ./scripts)
  4. # Check all of the plugins directories, if they exist
  5. if [ -d plugins ]
  6. then
  7. directories+=(plugins/*/scripts)
  8. fi
  9. # Enumerate all of the Groovy files
  10. files=()
  11. for dir in $directories;
  12. do
  13. if [ -d $dir ]
  14. then
  15. files+=($dir/[^_]*.groovy)
  16. fi
  17. done
  18. # Don't try to basename ()
  19. if [ ${#files} -eq 0 ];
  20. then
  21. return
  22. fi
  23. scripts=()
  24. for file in $files
  25. do
  26. # - Strip the path
  27. # - Remove all scripts with a leading '_'
  28. # - PackagePlugin_.groovy -> PackagePlugin
  29. # - PackagePlugin -> Package-Plugin
  30. # - Package-Plugin -> package-plugin
  31. command=$(basename $file \
  32. | sed -E -e 's/^_?([^_]+)_?.groovy/\1/'\
  33. -e 's/([a-z])([A-Z])/\1-\2/g' \
  34. | tr "[:upper:]" "[:lower:]" \
  35. | sort \
  36. | uniq)
  37. scripts+=($command)
  38. done
  39. echo $scripts
  40. }
  41. _grails() {
  42. if (( CURRENT == 2 )); then
  43. scripts=( $(_enumerateGrailsScripts) )
  44. if [ ${#scripts} -ne 0 ];
  45. then
  46. _multi_parts / scripts
  47. return
  48. fi
  49. fi
  50. _files
  51. }
  52. compdef _grails grails