rake-fast.plugin.zsh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # rake-fast
  2. # Fast rake autocompletion plugin for oh-my-zsh
  3. # This script caches the output for later usage and significantly speeds it up.
  4. # It generates a .rake_tasks file in parallel to the Rakefile.
  5. # You'll want to add `.rake_tasks` to your global .git_ignore file:
  6. # https://help.github.com/articles/ignoring-files#global-gitignore
  7. # You can force .rake_tasks to refresh with:
  8. # $ rake_refresh
  9. # This is entirely based on Ullrich Schäfer's work
  10. # (https://github.com/robb/.dotfiles/pull/10/),
  11. # which is inspired by this Ruby on Rails trick from 2006:
  12. # http://weblog.rubyonrails.org/2006/3/9/fast-rake-task-completion-for-zsh/
  13. # Author: Kevin Bongart
  14. # contact@kevinbongart.net
  15. # http://kevinbongart.net
  16. # https://github.com/KevinBongart
  17. _rake_refresh () {
  18. if [ -f .rake_tasks ]; then
  19. rm .rake_tasks
  20. fi
  21. echo "Generating .rake_tasks..." > /dev/stderr
  22. _rake_generate
  23. cat .rake_tasks
  24. }
  25. _rake_does_task_list_need_generating () {
  26. if [ ! -f .rake_tasks ]; then return 0;
  27. else
  28. accurate=$(stat -f%m .rake_tasks)
  29. changed=$(stat -f%m Rakefile)
  30. return $(expr $accurate '>=' $changed)
  31. fi
  32. }
  33. _rake_generate () {
  34. rake --silent --tasks | cut -d " " -f 2 > .rake_tasks
  35. }
  36. _rake () {
  37. if [ -f Rakefile ]; then
  38. if _rake_does_task_list_need_generating; then
  39. echo "\nGenerating .rake_tasks..." > /dev/stderr
  40. _rake_generate
  41. fi
  42. compadd `cat .rake_tasks`
  43. fi
  44. }
  45. compdef _rake rake
  46. alias rake_refresh='_rake_refresh'