_vagrant 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 suspended 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. 'snapshot:Manage snapshots with the guest machine'
  28. 'ssh:SSH into the currently running environment'
  29. 'ssh-config:Outputs .ssh/config valid syntax for connecting to this environment via ssh'
  30. 'status:Shows the status of the current Vagrant environment'
  31. 'suspend:Suspends the currently running vagrant environment'
  32. 'snapshot:Used to manage snapshots with the guest machine'
  33. 'up:Creates the vagrant environment'
  34. 'version:Prints current and latest Vagrant version'
  35. '--help:[TASK] Describe available tasks or one specific task'
  36. '--version:Prints the Vagrant version information'
  37. )
  38. local -a _box_arguments
  39. _box_arguments=(
  40. 'add:ADDRESS Adds a box to the system'
  41. 'help:COMMAND List subcommands'
  42. 'list:Lists all installed boxes'
  43. 'outdated:Checks if a box has newer version'
  44. 'remove:NAME Removes a box from the system'
  45. 'repackage:NAME PROVIDER VERSION Repackages an installed box into a `.box` file'
  46. 'update:Updates box to a newer version, if available'
  47. )
  48. __task_list ()
  49. {
  50. local expl
  51. declare -a tasks
  52. tasks=(box destroy halt init package provision reload resume ssh ssh_config status suspend up version)
  53. _wanted tasks expl 'help' compadd $tasks
  54. }
  55. __box_list ()
  56. {
  57. _wanted application expl 'command' compadd $(command vagrant box list | sed -e 's/ /\\ /g')
  58. }
  59. __vm_list ()
  60. {
  61. _wanted application expl 'command' compadd $(command grep Vagrantfile -oe '^[^#]*\.vm\.define *[:"]\([a-zA-Z0-9_-]\+\)' 2>/dev/null | awk '{print substr($2, 2)}')
  62. _wanted application expl 'command' compadd $(command ls .vagrant/machines/ 2>/dev/null)
  63. }
  64. __vagrant-box ()
  65. {
  66. local curcontext="$curcontext" state line
  67. typeset -A opt_args
  68. _arguments -C \
  69. ':command:->command' \
  70. '*::options:->options'
  71. case $state in
  72. (command)
  73. _describe -t commands "vagrant subcommand" _box_arguments
  74. return
  75. ;;
  76. (options)
  77. case $line[1] in
  78. (repackage|remove)
  79. _arguments ':feature:__box_list'
  80. ;;
  81. esac
  82. ;;
  83. esac
  84. }
  85. local expl
  86. local -a boxes installed_boxes
  87. local curcontext="$curcontext" state line
  88. typeset -A opt_args
  89. _arguments -C \
  90. ':command:->command' \
  91. '*::options:->options'
  92. case $state in
  93. (command)
  94. _describe -t commands "vagrant subcommand" _1st_arguments
  95. return
  96. ;;
  97. (options)
  98. case $line[1] in
  99. (help)
  100. _arguments ':feature:__task_list'
  101. ;;
  102. (box)
  103. __vagrant-box
  104. ;;
  105. (up|provision|package|destroy|reload|ssh|ssh-config|halt|resume|status)
  106. _arguments ':feature:__vm_list'
  107. esac
  108. ;;
  109. esac