_vagrant 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. '--help:[TASK] Describe available tasks or one specific task'
  21. '--version:Prints the Vagrant version information'
  22. )
  23. local -a _box_arguments
  24. _box_arguments=(
  25. 'add:NAME URI Add a box to the system'
  26. 'help:COMMAND Describe subcommands or one specific subcommand'
  27. 'list:Lists all installed boxes'
  28. 'remove:NAME Remove a box from the system'
  29. 'repackage:NAME Repackage an installed box into a `.box` file.'
  30. )
  31. __task_list ()
  32. {
  33. local expl
  34. declare -a tasks
  35. tasks=(box destroy halt init package provision reload resume ssh ssh_config status suspend up version)
  36. _wanted tasks expl 'help' compadd $tasks
  37. }
  38. __box_list ()
  39. {
  40. _wanted application expl 'command' compadd $(command ls -1 $HOME/.vagrant/boxes 2>/dev/null| sed -e 's/ /\\ /g')
  41. }
  42. __vm_list ()
  43. {
  44. _wanted application expl 'command' compadd $(command grep Vagrantfile -oe '^[^#]*\.vm\.define *:\([a-zA-Z0-9]\+\)' 2>/dev/null | cut -d: -f2)
  45. }
  46. __vagrant-box ()
  47. {
  48. local curcontext="$curcontext" state line
  49. typeset -A opt_args
  50. _arguments -C \
  51. ':command:->command' \
  52. '*::options:->options'
  53. case $state in
  54. (command)
  55. _describe -t commands "gem subcommand" _box_arguments
  56. return
  57. ;;
  58. (options)
  59. case $line[1] in
  60. (repackage|remove)
  61. _arguments ':feature:__box_list'
  62. ;;
  63. esac
  64. ;;
  65. esac
  66. }
  67. local expl
  68. local -a boxes installed_boxes
  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 "gem subcommand" _1st_arguments
  77. return
  78. ;;
  79. (options)
  80. case $line[1] in
  81. (help)
  82. _arguments ':feature:__task_list'
  83. ;;
  84. (box)
  85. __vagrant-box
  86. ;;
  87. (up|provision|package|destroy|reload|ssh|halt|resume|status)
  88. _arguments ':feature:__vm_list'
  89. esac
  90. ;;
  91. esac