rake-fast.plugin.zsh 851 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. _rake_refresh () {
  2. if [ -f .rake_tasks ]; then
  3. rm .rake_tasks
  4. fi
  5. echo "Generating .rake_tasks..." > /dev/stderr
  6. _rake_generate
  7. cat .rake_tasks
  8. }
  9. _rake_does_task_list_need_generating () {
  10. if [ ! -f .rake_tasks ]; then return 0;
  11. else
  12. if [[ "$OSTYPE" = darwin* ]]; then
  13. accurate=$(stat -f%m .rake_tasks)
  14. changed=$(stat -f%m Rakefile)
  15. else
  16. accurate=$(stat -c%Y .rake_tasks)
  17. changed=$(stat -c%Y Rakefile)
  18. fi
  19. return $(expr $accurate '>=' $changed)
  20. fi
  21. }
  22. _rake_generate () {
  23. rake --silent --tasks | cut -d " " -f 2 > .rake_tasks
  24. }
  25. _rake () {
  26. if [ -f Rakefile ]; then
  27. if _rake_does_task_list_need_generating; then
  28. echo "\nGenerating .rake_tasks..." > /dev/stderr
  29. _rake_generate
  30. fi
  31. compadd `cat .rake_tasks`
  32. fi
  33. }
  34. compdef _rake rake
  35. alias rake_refresh='_rake_refresh'