_vagrant 4.1 KB

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