_vagrant 3.3 KB

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