_vagrant 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #compdef vagrant
  2. #autoload
  3. # vagrant zsh completion
  4. local -a _1st_arguments
  5. _1st_arguments=(
  6. 'box:Box commands'
  7. 'destroy:Destroys the vagrant environment'
  8. 'halt:Halts the currently running vagrant environment'
  9. 'help:[TASK] Describe available tasks or one specific task'
  10. 'init:[box_name] [box_url] Initializes current folder for Vagrant usage'
  11. 'package:Packages a vagrant environment for distribution'
  12. 'provision:Run the provisioner'
  13. 'reload:Reload the vagrant environment'
  14. 'resume:Resumes a suspend vagrant environment'
  15. 'ssh:SSH into the currently running environment'
  16. 'ssh_config:outputs .ssh/config valid syntax for connecting to this environment via ssh.'
  17. 'status:Shows the status of the current Vagrant environment.'
  18. 'suspend:Suspends the currently running vagrant environment'
  19. 'up:Creates the vagrant environment'
  20. 'version:Prints the Vagrant version information'
  21. )
  22. local -a _box_arguments
  23. _box_arguments=(
  24. 'add:NAME URI Add a box to the system'
  25. 'help:COMMAND Describe subcommands or one specific subcommand'
  26. 'list:Lists all installed boxes'
  27. 'remove:NAME Remove a box from the system'
  28. 'repackage:NAME Repackage an installed box into a `.box` file.'
  29. )
  30. __task_list ()
  31. {
  32. local expl
  33. declare -a tasks
  34. tasks=(box destroy halt init package provision reload resume ssh ssh_config status suspend up version)
  35. _wanted tasks expl 'help' compadd $tasks
  36. }
  37. __box_list ()
  38. {
  39. _wanted application expl 'command' compadd $(command ls -1 $HOME/.vagrant/boxes 2>/dev/null| sed -e 's/ /\\ /g')
  40. }
  41. __vm_list ()
  42. {
  43. _wanted application expl 'command' compadd $(command grep Vagrantfile -oe '^[^#]*\.vm\.define *:\([a-zA-Z0-9]\+\)' 2>/dev/null | cut -d: -f2)
  44. }
  45. __vagrant-box ()
  46. {
  47. local curcontext="$curcontext" state line
  48. typeset -A opt_args
  49. _arguments -C \
  50. ':command:->command' \
  51. '*::options:->options'
  52. case $state in
  53. (command)
  54. _describe -t commands "gem subcommand" _box_arguments
  55. return
  56. ;;
  57. (options)
  58. case $line[1] in
  59. (repackage|remove)
  60. _arguments ':feature:__box_list'
  61. ;;
  62. esac
  63. ;;
  64. esac
  65. }
  66. local expl
  67. local -a boxes installed_boxes
  68. local curcontext="$curcontext" state line
  69. typeset -A opt_args
  70. _arguments -C \
  71. ':command:->command' \
  72. '*::options:->options'
  73. case $state in
  74. (command)
  75. _describe -t commands "gem subcommand" _1st_arguments
  76. return
  77. ;;
  78. (options)
  79. case $line[1] in
  80. (help)
  81. _arguments ':feature:__task_list'
  82. ;;
  83. (box)
  84. __vagrant-box
  85. ;;
  86. (up|provision|package|destroy|reload|ssh|halt|resume|status)
  87. _arguments ':feature:__vm_list'
  88. esac
  89. ;;
  90. esac