_vagrant 2.8 KB

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