rake-fast.plugin.zsh 842 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. _rake_does_task_list_need_generating () {
  2. [[ ! -f .rake_tasks ]] || [[ Rakefile -nt .rake_tasks ]] || { _is_rails_app && _tasks_changed }
  3. }
  4. _is_rails_app () {
  5. [[ -e "bin/rails" ]] || [[ -e "script/rails" ]]
  6. }
  7. _tasks_changed () {
  8. local -a files
  9. files=(lib/tasks lib/tasks/**/*(N))
  10. for file in $files; do
  11. if [[ "$file" -nt .rake_tasks ]]; then
  12. return 0
  13. fi
  14. done
  15. return 1
  16. }
  17. _rake_generate () {
  18. rake --silent --tasks | cut -d " " -f 2 > .rake_tasks
  19. }
  20. _rake () {
  21. if [[ -f Rakefile ]]; then
  22. if _rake_does_task_list_need_generating; then
  23. echo "\nGenerating .rake_tasks..." >&2
  24. _rake_generate
  25. fi
  26. compadd $(cat .rake_tasks)
  27. fi
  28. }
  29. compdef _rake rake
  30. rake_refresh () {
  31. [[ -f .rake_tasks ]] && rm -f .rake_tasks
  32. echo "Generating .rake_tasks..." >&2
  33. _rake_generate
  34. cat .rake_tasks
  35. }