cake.plugin.zsh 670 B

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