cap.plugin.zsh 871 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. stat -f%m . > /dev/null 2>&1
  2. if [ "$?" = 0 ]; then
  3. stat_cmd=(stat -f%m)
  4. else
  5. stat_cmd=(stat -L --format=%y)
  6. fi
  7. # Cache filename
  8. _cap_show_undescribed_tasks=0
  9. # Cache filename
  10. _cap_task_cache_file='.cap_task_cache'
  11. _cap_get_task_list () {
  12. if [ ${_cap_show_undescribed_tasks} -eq 0 ]; then
  13. cap -T | grep '^cap' | cut -d " " -f 2
  14. else
  15. cap -vT | grep '^cap' | cut -d " " -f 2
  16. fi
  17. }
  18. _cap_does_task_list_need_generating () {
  19. if [ ! -f ${_cap_task_cache_file} ]; then return 0;
  20. else
  21. accurate=$($stat_cmd $_cap_task_cache_file)
  22. changed=$($stat_cmd config/deploy.rb)
  23. return $(expr $accurate '>=' $changed)
  24. fi
  25. }
  26. function _cap () {
  27. if [ -f config/deploy.rb ]; then
  28. if _cap_does_task_list_need_generating; then
  29. _cap_get_task_list > ${_cap_task_cache_file}
  30. fi
  31. compadd `cat ${_cap_task_cache_file}`
  32. fi
  33. }
  34. compdef _cap cap