_vagrant 3.0 KB

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