cake.plugin.zsh 780 B

123456789101112131415161718192021222324252627282930313233343536
  1. # Set this to 1 if you want to cache the tasks
  2. _cake_cache_task_list=1
  3. # Cache filename
  4. _cake_task_cache_file='.cake_task_cache'
  5. _cake_get_target_list () {
  6. cake | grep '^cake ' | sed -e "s/cake \([^ ]*\) .*/\1/" | grep -v '^$'
  7. }
  8. _cake_does_target_list_need_generating () {
  9. if [ ${_cake_cache_task_list} -eq 0 ]; then
  10. return 1;
  11. fi
  12. if [ ! -f ${_cake_task_cache_file} ]; then return 0;
  13. else
  14. accurate=$(stat -f%m $_cake_task_cache_file)
  15. changed=$(stat -f%m Cakefile)
  16. return $(expr $accurate '>=' $changed)
  17. fi
  18. }
  19. _cake () {
  20. if [ -f Cakefile ]; then
  21. if _cake_does_target_list_need_generating; then
  22. _cake_get_target_list > ${_cake_task_cache_file}
  23. compadd `cat ${_cake_task_cache_file}`
  24. else
  25. compadd `_cake_get_target_list`
  26. fi
  27. fi
  28. }
  29. compdef _cake cake