_kitchen 959 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # author: Peter Eisentraut
  2. # source: https://gist.github.com/petere/10307599
  3. # compdef kitchen
  4. _kitchen() {
  5. local curcontext="$curcontext" state line
  6. typeset -A opt_args
  7. _arguments '1: :->cmds'\
  8. '2: :->args'
  9. case $state in
  10. cmds)
  11. _arguments "1:Commands:(console converge create destroy diagnose driver help init list login setup test verify version)"
  12. ;;
  13. args)
  14. case $line[1] in
  15. converge|create|destroy|diagnose|list|setup|test|verify)
  16. compadd "$@" all
  17. _kitchen_instances
  18. ;;
  19. login)
  20. _kitchen_instances
  21. ;;
  22. esac
  23. ;;
  24. esac
  25. }
  26. _kitchen_instances() {
  27. if [[ $_kitchen_instances_cache_dir != $PWD ]]; then
  28. unset _kitchen_instances_cache
  29. fi
  30. if [[ ${+_kitchen_instances_cache} -eq 0 ]]; then
  31. _kitchen_instances_cache=(${(f)"$(bundle exec kitchen list -b 2>/dev/null || kitchen list -b 2>/dev/null)"})
  32. _kitchen_instances_cache_dir=$PWD
  33. fi
  34. compadd -a _kitchen_instances_cache
  35. }
  36. _kitchen "$@"