_vagrant 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 remotely shared Vagrant environment'
  8. 'destroy:Destroys the vagrant environment'
  9. 'docker-logs:Outputs the logs from the Docker container'
  10. 'docker-run:Run a one-off command in the context of a container'
  11. 'global-status:Reports the status of all active Vagrant environments on the system'
  12. 'halt:Halts the currently running vagrant environment'
  13. 'help:Shows the help for a subcommand'
  14. 'init:[box_name] [box_url] Initializes current folder for Vagrant usage'
  15. 'list-commands:Outputs all available Vagrant subcommands, even non-primary ones'
  16. 'login:Authenticates against a Vagrant Cloud server to access protected boxes'
  17. 'package:Packages a vagrant environment for distribution'
  18. 'plugin:Plugin commands'
  19. 'provision:Run the provisioner'
  20. 'push:Deploys code in this environment to a configured destination'
  21. 'rdp:Connects to machine via RDP'
  22. 'reload:Reload the vagrant environment'
  23. 'resume:Resumes a suspend vagrant environment'
  24. 'rsync:Syncs rsync synced folders to remote machine'
  25. 'rsync-auto:Syncs rsync synced folders automatically when files change'
  26. 'share:Shares your Vagrant environment with anyone in the world'
  27. 'ssh:SSH into the currently running environment'
  28. 'ssh-config:Outputs .ssh/config valid syntax for connecting to this environment via ssh'
  29. 'status:Shows the status of the current Vagrant environment'
  30. 'suspend:Suspends the currently running vagrant environment'
  31. 'up:Creates the vagrant environment'
  32. 'version:Prints current and latest Vagrant version'
  33. '--help:[TASK] Describe available tasks or one specific task'
  34. '--version:Prints the Vagrant version information'
  35. )
  36. local -a _box_arguments
  37. _box_arguments=(
  38. 'add:ADDRESS Adds a box to the system'
  39. 'help:COMMAND List subcommands'
  40. 'list:Lists all installed boxes'
  41. 'outdated:Checks if a box has newer version'
  42. 'remove:NAME Removes a box from the system'
  43. 'repackage:NAME PROVIDER VERSION Repackages an installed box into a `.box` file'
  44. 'update:Updates box to a newer version, if available'
  45. )
  46. __task_list ()
  47. {
  48. local expl
  49. declare -a tasks
  50. tasks=(box destroy halt init package provision reload resume ssh ssh_config status suspend up version)
  51. _wanted tasks expl 'help' compadd $tasks
  52. }
  53. __box_list ()
  54. {
  55. _wanted application expl 'command' compadd $(command vagrant box list | sed -e 's/ /\\ /g')
  56. }
  57. __vm_list ()
  58. {
  59. _wanted application expl 'command' compadd $(command grep Vagrantfile -oe '^[^#]*\.vm\.define *[:"]\([a-zA-Z0-9_-]\+\)' 2>/dev/null | awk '{print substr($2, 2)}')
  60. _wanted application expl 'command' compadd $(command ls .vagrant/machines/ 2>/dev/null)
  61. }
  62. __vagrant-box ()
  63. {
  64. local curcontext="$curcontext" state line
  65. typeset -A opt_args
  66. _arguments -C \
  67. ':command:->command' \
  68. '*::options:->options'
  69. case $state in
  70. (command)
  71. _describe -t commands "gem subcommand" _box_arguments
  72. return
  73. ;;
  74. (options)
  75. case $line[1] in
  76. (repackage|remove)
  77. _arguments ':feature:__box_list'
  78. ;;
  79. esac
  80. ;;
  81. esac
  82. }
  83. local expl
  84. local -a boxes installed_boxes
  85. local curcontext="$curcontext" state line
  86. typeset -A opt_args
  87. _arguments -C \
  88. ':command:->command' \
  89. '*::options:->options'
  90. case $state in
  91. (command)
  92. _describe -t commands "gem subcommand" _1st_arguments
  93. return
  94. ;;
  95. (options)
  96. case $line[1] in
  97. (help)
  98. _arguments ':feature:__task_list'
  99. ;;
  100. (box)
  101. __vagrant-box
  102. ;;
  103. (up|provision|package|destroy|reload|ssh|ssh-config|halt|resume|status)
  104. _arguments ':feature:__vm_list'
  105. esac
  106. ;;
  107. esac