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