grails.plugin.zsh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. _enumerateGrailsScripts() {
  2. # Default directoryies
  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