_vagrant 3.1 KB

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