├── LICENSE ├── Makefile ├── README.rst └── vagrant-bash-completion ├── DEBIAN ├── conffiles └── control └── etc └── bash_completion.d └── vagrant /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2015-2017 Six 4 | Copyright (c) 2014 Kura 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the 'Software'), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: deb install userinstall uninstall useruninstall 2 | 3 | deb: 4 | fakeroot dpkg-deb -z8 -Zgzip --build vagrant-bash-completion . 5 | 6 | install: 7 | install -m 0644 vagrant-bash-completion/etc/bash_completion.d/vagrant /etc/bash_completion.d/ 8 | 9 | userinstall: 10 | install -m 0664 vagrant-bash-completion/etc/bash_completion.d/vagrant ~/.bash_completion.d/ 11 | 12 | uninstall: 13 | rm /etc/bash_completion.d/vagrant 14 | 15 | useruninstall: 16 | rm ~/.bash_completion.d/vagrant 17 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | This is a fork of Kura's `vagrant-bash-completion`_ script with a number of significant improvements. These are a few of them: 2 | 3 | * compatible with Vagrant 1.9.3 4 | * completions for all subcommands and option flags 5 | * completions for vagrant-share plugin 6 | * optional dynamic completion if Vagrant is updated or extended (this is slow, but caching is used to speed up future use) 7 | * support for VAGRANT_HOME (See `#35`_) 8 | 9 | Installation 10 | ============ 11 | 12 | See `latest release`_ for *.deb* package or choose from one of the following installation methods. 13 | 14 | Easy Install 15 | ------------ 16 | 17 | To install system-wide without downloading the repository: 18 | 19 | .. code:: bash 20 | 21 | wget -q https://raw.github.com/brbsix/vagrant-bash-completion/master/vagrant-bash-completion/etc/bash_completion.d/vagrant 22 | sudo install -m 0644 vagrant /etc/bash_completion.d/ 23 | 24 | System Install 25 | -------------- 26 | 27 | To install system-wide, run the following from within the repository: 28 | 29 | ``sudo make install`` 30 | 31 | User Install 32 | ------------ 33 | 34 | To install for user, run the following from within the repository: 35 | 36 | ``make userinstall`` 37 | 38 | Note: You'll need to ensure that *~/.bash_completion.d/vagrant* is sourced in your shell. I recommend appending the following code to your *.bashrc*. 39 | 40 | .. code:: bash 41 | 42 | # Load user completion scripts in ~/.bash_completion.d 43 | while IFS= read -r path; do 44 | . "$path" 45 | done < <(find -L ~/.bash_completion.d -type f) 46 | 47 | 48 | Build Instructions 49 | ================== 50 | 51 | To build the *.deb* package, ensure ``fakeroot`` is installed then run the following from within the repository: 52 | 53 | ``make deb`` 54 | 55 | 56 | License 57 | ======= 58 | 59 | This software is licensed using the MIT License. 60 | The license is provided in the `source code repository`_. 61 | 62 | 63 | Prior Contributors 64 | =================== 65 | 66 | +------------------------+-------------------------------------------------------------------------------------------+ 67 | | `Kura`_ | https://github.com/kura/vagrant-bash-completion/blob/master/etc/bash_completion.d/vagrant | 68 | +------------------------+-------------------------------------------------------------------------------------------+ 69 | | `Nikita Fedyashev`_ | https://github.com/nfedyashev/bash-it/blob/master/plugins/vagrant.plugins.bash | 70 | +------------------------+-------------------------------------------------------------------------------------------+ 71 | 72 | .. _vagrant-bash-completion: https://github.com/kura/vagrant-bash-completion 73 | .. _#35: https://github.com/kura/vagrant-bash-completion/pull/35 74 | .. _latest release: https://github.com/brbsix/vagrant-bash-completion/releases/latest 75 | .. _source code repository: https://github.com/brbsix/vagrant-bash-completion/blob/master/LICENSE 76 | .. _Kura: https://github.com/kura 77 | .. _Nikita Fedyashev: https://github.com/nfedyashev 78 | -------------------------------------------------------------------------------- /vagrant-bash-completion/DEBIAN/conffiles: -------------------------------------------------------------------------------- 1 | /etc/bash_completion.d/vagrant 2 | -------------------------------------------------------------------------------- /vagrant-bash-completion/DEBIAN/control: -------------------------------------------------------------------------------- 1 | Package: vagrant-bash-completion 2 | Priority: optional 3 | Section: shells 4 | Installed-Size: 38 5 | Maintainer: Six 6 | Architecture: all 7 | Version: 0.3.0 8 | Depends: bash-completion (>=1.0) 9 | Description: vagrant completions for bash 10 | Homepage: https://github.com/brbsix/vagrant-bash-completion 11 | Bugs: https://github.com/brbsix/vagrant-bash-completion/issues 12 | -------------------------------------------------------------------------------- /vagrant-bash-completion/etc/bash_completion.d/vagrant: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # (The MIT License) 4 | # 5 | # Copyright (c) 2014 Kura 6 | # Copyright (c) 2015-2017 Six 7 | # 8 | # Permission is hereby granted, free of charge, to any person obtaining a copy 9 | # of this software and associated documentation files (the 'Software'), to deal 10 | # in the Software without restriction, including without limitation the rights 11 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | # copies of the Software, and to permit persons to whom the Software is 13 | # furnished to do so, subject to the following conditions: 14 | # 15 | # The above copyright notice and this permission notice shall be included in all 16 | # copies or substantial portions of the Software. 17 | # 18 | # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | # SOFTWARE. 25 | 26 | 27 | # ensure vagrant or vagrant.exe is on PATH 28 | for vagrant in vagrant vagrant.exe; do 29 | hash "$vagrant" &>/dev/null && break 30 | done && { 31 | 32 | # static completions are much faster but less accurate 33 | __VAGRANT_STATIC_COMPLETION=1 34 | 35 | # store static completions 36 | __VAGRANT_COMMANDS=(box cap connect destroy docker-logs docker-run 37 | global-status halt help init list-commands login package plugin 38 | port powershell provider provision push rdp reload resume rsync 39 | rsync-auto share snapshot ssh ssh-config status suspend up version) 40 | 41 | __VAGRANT_BOX_COMMANDS=(add list outdated prune remove repackage update) 42 | 43 | __VAGRANT_PLUGIN_COMMANDS=(install license list uninstall update) 44 | 45 | __VAGRANT_SNAPSHOT_COMMANDS=(back delete go list take) 46 | 47 | __vagrant_complete(){ 48 | local command_options='' 49 | 50 | command_options=$(__vagrant_list_options "$@") 51 | [[ -z $command_options ]] && return 1 52 | 53 | readarray -t COMPREPLY < <(compgen -W "$command_options" -- "$cur") 54 | 55 | return 0 56 | } 57 | 58 | __vagrant_complete_providers(){ 59 | local providers=() 60 | 61 | providers=(docker hyperv libvirt lxc virtualbox vmware_fusion) 62 | 63 | readarray -t COMPREPLY < <(compgen -W "${providers[*]}" -- "$cur") 64 | 65 | return 0 66 | } 67 | 68 | __vagrant_complete_provisioners(){ 69 | local provisioners=() 70 | 71 | provisioners=(ansible ansible_local cfengine chef_apply \ 72 | chef_client chef_solo chef_zero docker file \ 73 | puppet puppet_server salt shell) 74 | 75 | readarray -t COMPREPLY < <(compgen -W "${provisioners[*]}" -- "$cur") 76 | 77 | return 0 78 | } 79 | 80 | __vagrant_get_boxes(){ 81 | 82 | local vagrant_boxes='' 83 | 84 | vagrant_boxes=$(find "${VAGRANT_HOME:-$HOME/.vagrant.d}/boxes" -maxdepth 1 -mindepth 1 -type d -printf '%P\n' 2>/dev/null | sed 's/-VAGRANTSLASH-/\//') 85 | 86 | [[ -z $vagrant_boxes ]] && return 1 87 | 88 | echo "$vagrant_boxes" 89 | } 90 | 91 | __vagrant_get_commands(){ 92 | 93 | local vagrant_commands='' vagrant_output='' 94 | 95 | # local must be declared beforehand in order to return an accurate exit status here 96 | vagrant_output=$(vagrant list-commands 2>/dev/null) || return 1 97 | 98 | # `NF != 0` is there solely to insure against any errata appended to list-commands output at a later date 99 | vagrant_commands=$(awk '/^$/ {while (getline && NF != 0) print $1}' <<<"$vagrant_output" | sort) 100 | 101 | [[ -z $vagrant_commands ]] && return 1 102 | 103 | echo "$vagrant_commands" 104 | } 105 | 106 | __vagrant_get_environments(){ 107 | 108 | local vagrant_environments='' vagrant_output='' 109 | 110 | # local must be declared beforehand in order to return an accurate exit status here 111 | vagrant_output=$(vagrant global-status 2>/dev/null) || return 1 112 | 113 | vagrant_environments=$(awk '/^-+$/ {while (getline && NF != 0) print $1}' <<<"$vagrant_output") 114 | 115 | [[ -z $vagrant_environments ]] && return 1 116 | 117 | echo "$vagrant_environments" 118 | } 119 | 120 | __vagrant_get_not_off(){ 121 | 122 | local not_off='' reply='' 123 | 124 | not_off=$(__vagrant_get_not_off_local) 125 | 126 | reply=$? 127 | 128 | if (( reply == 1 )); then 129 | return 1 130 | elif (( reply == 100 )); then 131 | not_off=$(__vagrant_get_not_off_global) || return 1 132 | fi 133 | 134 | echo "$not_off" 135 | } 136 | 137 | __vagrant_get_not_off_global(){ 138 | 139 | local not_off='' vagrant_output='' 140 | 141 | # local must be declared beforehand in order to return an accurate exit status here 142 | vagrant_output=$(vagrant global-status 2>/dev/null) || return 1 143 | 144 | not_off=$(awk '/^-+$/ {while (getline && NF != 0) if ($4 != "poweroff") print $1}' <<<"$vagrant_output") 145 | 146 | [[ -z $not_off ]] && return 1 147 | 148 | echo "$not_off" 149 | } 150 | 151 | __vagrant_get_not_off_local(){ 152 | 153 | local not_off='' vagrant_output='' 154 | 155 | # local must be declared beforehand in order to return an accurate exit status here 156 | vagrant_output=$(vagrant status 2>/dev/null) || return 100 157 | 158 | not_off=$(awk '/^$/ {while (getline && NF != 0) if ($2 != "poweroff") print $1}' <<<"$vagrant_output") 159 | 160 | [[ -z $not_off ]] && return 1 161 | 162 | echo "$not_off" 163 | } 164 | 165 | __vagrant_get_not_running(){ 166 | 167 | local not_running='' reply='' 168 | 169 | not_running=$(__vagrant_get_not_running_local) 170 | 171 | reply=$? 172 | 173 | if (( reply == 1 )); then 174 | return 1 175 | elif (( reply == 100 )); then 176 | not_running=$(__vagrant_get_not_running_global) || return 1 177 | fi 178 | 179 | echo "$not_running" 180 | } 181 | 182 | __vagrant_get_not_running_global(){ 183 | 184 | local not_running='' vagrant_output='' 185 | 186 | # local must be declared beforehand in order to return an accurate exit status here 187 | vagrant_output=$(vagrant global-status 2>/dev/null) || return 1 188 | 189 | not_running=$(awk '/^-+$/ {while (getline && NF != 0) if ($4 != "running") print $1}' <<<"$vagrant_output") 190 | 191 | [[ -z $not_running ]] && return 1 192 | 193 | echo "$not_running" 194 | } 195 | 196 | 197 | __vagrant_get_not_running_local(){ 198 | 199 | local not_running='' vagrant_output='' 200 | 201 | # local must be declared beforehand in order to return an accurate exit status here 202 | vagrant_output=$(vagrant status 2>/dev/null) || return 100 203 | 204 | not_running=$(awk '/^$/ {while (getline && NF != 0) if ($2 != "running") print $1}' <<<"$vagrant_output") 205 | 206 | [[ -z $not_running ]] && return 1 207 | 208 | echo "$not_running" 209 | } 210 | 211 | # ignore current word and actions 212 | __vagrant_get_options(){ 213 | 214 | local arg 215 | 216 | for arg in "${COMP_WORDS[@]:0:$((${#COMP_WORDS[@]}-1))}"; do 217 | [[ $arg = -* ]] && echo "$arg" 218 | done 219 | 220 | return 0 221 | } 222 | 223 | __vagrant_get_plugins(){ 224 | 225 | local vagrant_plugins='' 226 | 227 | vagrant_plugins=$(vagrant plugin list 2>/dev/null | awk '{print $1}') 228 | 229 | [[ -z $vagrant_plugins ]] && return 1 230 | 231 | echo "$vagrant_plugins" 232 | } 233 | 234 | __vagrant_get_snapshots(){ 235 | 236 | local vagrant_output='' vagrant_snapshots='' 237 | 238 | # local must be declared beforehand in order to return an accurate exit status here 239 | vagrant_output=$(vagrant snapshot list 2>/dev/null) || return 1 240 | 241 | vagrant_snapshots=$(awk '$1 ~ /Name:/ {print $2}' <<<"$vagrant_output") 242 | 243 | [[ -z $vagrant_snapshots ]] && return 1 244 | 245 | echo "$vagrant_snapshots" 246 | } 247 | 248 | __vagrant_get_subcommands(){ 249 | 250 | local vagrant_output='' vagrant_subcommands='' 251 | 252 | # local must be declared beforehand in order to return an accurate exit status here 253 | vagrant_output=$(vagrant help "$1" 2>/dev/null) || return 1 254 | 255 | vagrant_subcommands=$(awk '/^Available subcommands:$/ {while (getline && NF == 1) print $1}' <<<"$vagrant_output") 256 | # vagrant_subcommands=$(awk '/^ [a-z]+$/ {print $1}' <<<"$vagrant_output") 257 | 258 | [[ -z $vagrant_subcommands ]] && return 1 259 | 260 | echo "$vagrant_subcommands" 261 | } 262 | 263 | __vagrant_get_versions(){ 264 | 265 | local vagrant_output='' vagrant_versions='' 266 | 267 | # local must be declared beforehand in order to return an accurate exit status here 268 | vagrant_output=$(vagrant box list 2>/dev/null) || return 1 269 | 270 | vagrant_versions=$(awk '{sub(")$", "", $NF); print $NF}' <<<"$vagrant_output") 271 | 272 | [[ -z $vagrant_versions ]] && return 1 273 | 274 | echo "$vagrant_versions" 275 | } 276 | 277 | __vagrant_get_vms(){ 278 | 279 | local vagrant_output='' vagrant_vms='' 280 | 281 | # local must be declared beforehand in order to return an accurate exit status here 282 | vagrant_output=$(vagrant status 2>/dev/null) || return 1 283 | 284 | vagrant_vms=$(awk '/^$/ {while (getline && NF != 0) print $1}' <<<"$vagrant_output") 285 | 286 | [[ -z $vagrant_vms ]] && return 1 287 | 288 | echo "$vagrant_vms" 289 | } 290 | 291 | # ignore current word and options 292 | __vagrant_get_words(){ 293 | 294 | eval set -- "${COMP_WORDS[@]:0:$((${#COMP_WORDS[@]}-1))}" 295 | 296 | while (( $# > 0 )); do 297 | # some options consume an argument 298 | if [[ $1 =~ ^(--base|--box|--box-version|-c|--cacert|--capath|--cert|--checksum|--checksum-type|--command|--entry-point|--host|--include|--name|--output|--provider|--plugin-source|--plugin-version|--provision-with|--static-ip|-t|--token|--vagrantfile)$ ]]; then 299 | shift 300 | # share plugin options that consume an argument 301 | elif [[ $1 =~ ^(--domain|--http|--https|--name|--ssh-port)$ ]]; then 302 | shift 303 | elif [[ $1 != -* ]]; then 304 | echo "$1" 305 | fi 306 | shift 307 | done 308 | } 309 | 310 | # accept options as arguments and output unused options 311 | __vagrant_list_options(){ 312 | 313 | local arg args=() 314 | 315 | for arg in "$@"; do 316 | 317 | for option in "${options[@]}"; do 318 | # skip --include because it can be used multiple times 319 | [[ $option != --include && $option = "$arg" ]] && continue 2 320 | done 321 | 322 | args+=("$arg") 323 | 324 | done 325 | 326 | echo "${args[@]}" 327 | } 328 | 329 | __vagrant(){ 330 | 331 | local action='' cur='' options=() subaction='' words=() 332 | 333 | cur=${COMP_WORDS[COMP_CWORD]} 334 | prev=${COMP_WORDS[COMP_CWORD-1]} 335 | 336 | readarray -t options < <(__vagrant_get_options) 337 | readarray -t words < <(__vagrant_get_words) 338 | 339 | action=${words[1]} 340 | subaction=${words[2]} 341 | 342 | # NOTE: the following vars are cached in the global environment for speedy completion in the future 343 | # __vagrant_commands 344 | # __vagrant_box_commands 345 | # __vagrant_plugin_commands 346 | # __vagrant_snapshot_commands 347 | # __vagrant_virtualbox_vms 348 | 349 | if (( ${#words[@]} == 1 )); then 350 | 351 | if (( __VAGRANT_STATIC_COMPLETION == 1 )); then 352 | readarray -t COMPREPLY < <(compgen -W "${__VAGRANT_COMMANDS[*]}" -- "$cur") 353 | return 0 354 | fi 355 | 356 | # get vagrant commands only if they are not already cached 357 | [[ -z $__vagrant_commands ]] && { 358 | __vagrant_commands=$(__vagrant_get_commands) || return 1 359 | } 360 | 361 | readarray -t COMPREPLY < <(compgen -W "$__vagrant_commands" -- "$cur") 362 | 363 | return 0 364 | 365 | elif (( ${#words[@]} == 2 )); then 366 | 367 | case "$action" in 368 | 369 | box) 370 | if (( __VAGRANT_STATIC_COMPLETION == 1 )); then 371 | readarray -t COMPREPLY < <(compgen -W "${__VAGRANT_BOX_COMMANDS[*]}" -- "$cur") 372 | return 0 373 | fi 374 | 375 | # get box commands only if they are not already cached 376 | [[ -z $__vagrant_box_commands ]] && { 377 | __vagrant_box_commands=$(__vagrant_get_subcommands box) || return 1 378 | } 379 | 380 | readarray -t COMPREPLY < <(compgen -W "$__vagrant_box_commands" -- "$cur") 381 | 382 | return 0 383 | ;; 384 | 385 | cap) 386 | __vagrant_complete --check 387 | 388 | return $? 389 | ;; 390 | 391 | connect) 392 | [[ $prev = --static-ip ]] && return 0 393 | 394 | __vagrant_complete --disable-static-ip --ssh --static-ip 395 | 396 | return $? 397 | ;; 398 | 399 | destroy) 400 | local destroy_options='' environments='' 401 | 402 | destroy_options=$(__vagrant_list_options -f --force) 403 | environments=$(__vagrant_get_environments) || return 1 404 | 405 | readarray -t COMPREPLY < <(compgen -W "$destroy_options $environments" -- "$cur") 406 | 407 | return 0 408 | ;; 409 | 410 | docker-logs) 411 | __vagrant_complete --follow --no-follow --no-prefix --prefix 412 | 413 | return $? 414 | ;; 415 | 416 | docker-run) 417 | __vagrant_complete --detach --no-detach --no-rm --no-tty -r --rm -t --tty 418 | 419 | return $? 420 | ;; 421 | 422 | global-status) 423 | __vagrant_complete --prune 424 | 425 | return $? 426 | ;; 427 | 428 | halt|provision|resume|rsync|rsync-auto|ssh|ssh-config|suspend) 429 | local command_options='' not_off='' 430 | 431 | case "$action" in 432 | 433 | halt) 434 | command_options=$(__vagrant_list_options -f --force) 435 | ;; 436 | 437 | provision) 438 | if [[ $prev = --provision-with ]]; then 439 | __vagrant_complete_provisioners 440 | return $? 441 | fi 442 | 443 | command_options=$(__vagrant_list_options --provision-with) 444 | ;; 445 | 446 | rsync-auto) 447 | command_options=$(__vagrant_list_options --no-poll --poll) 448 | ;; 449 | 450 | ssh) 451 | [[ $prev =~ ^(-c|--command)$ ]] && return 0 452 | 453 | command_options=$(__vagrant_list_options -c --command -p --plain) 454 | ;; 455 | 456 | ssh-config) 457 | [[ $prev = --host ]] && return 0 458 | 459 | command_options=$(__vagrant_list_options --host) 460 | ;; 461 | 462 | esac 463 | 464 | not_off=$(__vagrant_get_not_off) || return 1 465 | 466 | readarray -t COMPREPLY < <(compgen -W "$command_options $not_off" -- "$cur") 467 | 468 | return 0 469 | ;; 470 | 471 | help) 472 | if (( __VAGRANT_STATIC_COMPLETION == 1 )); then 473 | readarray -t COMPREPLY < <(compgen -W "${__VAGRANT_COMMANDS[*]}" -- "$cur") 474 | return 0 475 | fi 476 | 477 | # get vagrant commands only if they are not already cached 478 | [[ -z $__vagrant_commands ]] && { 479 | __vagrant_commands=$(__vagrant_get_commands) || return 1 480 | } 481 | 482 | readarray -t COMPREPLY < <(compgen -W "$__vagrant_commands" -- "$cur") 483 | 484 | return 0 485 | ;; 486 | 487 | init) 488 | [[ $prev = --output ]] && return 0 489 | 490 | local box_list='' init_options='' 491 | 492 | init_options=$(__vagrant_list_options -f --force -m --minimal --output) 493 | box_list=$(__vagrant_get_boxes) || return 1 494 | 495 | readarray -t COMPREPLY < <(compgen -W "$init_options $box_list" -- "$cur") 496 | 497 | return 0 498 | ;; 499 | 500 | login) 501 | [[ $prev =~ ^(-t|--token)$ ]] && return 0 502 | 503 | __vagrant_complete -c --check -k --logout -t --token 504 | 505 | return $? 506 | ;; 507 | 508 | package) 509 | case $prev in 510 | --base) 511 | # get VirtualBox VMs only if they are not already cached 512 | [[ -z $__vagrant_virtualbox_vms ]] && { 513 | readarray -t __vagrant_virtualbox_vms < <(VBoxManage list vms 2>/dev/null | sed 's/ {.\+}$//') 514 | } 515 | 516 | readarray -t COMPREPLY < <(compgen -W "${__vagrant_virtualbox_vms[*]}" -- "$cur") 517 | 518 | return 0 519 | ;; 520 | --include|--vagrantfile) 521 | _filedir 522 | return $? 523 | ;; 524 | --output) 525 | return 0 526 | ;; 527 | esac 528 | 529 | __vagrant_complete --base --include --output --vagrantfile 530 | 531 | return $? 532 | ;; 533 | 534 | plugin) 535 | if (( __VAGRANT_STATIC_COMPLETION == 1 )); then 536 | readarray -t COMPREPLY < <(compgen -W "${__VAGRANT_PLUGIN_COMMANDS[*]}" -- "$cur") 537 | return 0 538 | fi 539 | 540 | # get plugin commands only if they are not already cached 541 | [[ -z $__vagrant_plugin_commands ]] && { 542 | __vagrant_plugin_commands=$(__vagrant_get_subcommands plugin) || return 1 543 | } 544 | 545 | readarray -t COMPREPLY < <(compgen -W "$__vagrant_plugin_commands" -- "$cur") 546 | 547 | return 0 548 | ;; 549 | 550 | port) 551 | [[ $prev = --guest ]] && return 0 552 | 553 | __vagrant_complete --guest --machine-readable 554 | 555 | return $? 556 | ;; 557 | 558 | powershell) 559 | [[ $prev =~ ^(-c|--command)$ ]] && return 0 560 | 561 | __vagrant_complete -c --command 562 | 563 | return $? 564 | ;; 565 | 566 | provider) 567 | __vagrant_complete --install --usable 568 | 569 | return $? 570 | ;; 571 | 572 | reload) 573 | if [[ $prev = --provision-with ]]; then 574 | __vagrant_complete_provisioners 575 | return $? 576 | fi 577 | 578 | local command_options='' vm_list='' 579 | 580 | command_options=$(__vagrant_list_options --no-provision --provision --provision-with) 581 | vm_list=$(__vagrant_get_vms) || return 1 582 | 583 | readarray -t COMPREPLY < <(compgen -W "$up_options $vm_list" -- "$cur") 584 | 585 | return 0 586 | ;; 587 | 588 | share) 589 | [[ $prev =~ ^(--domain|--http|--https|--name|--ssh-port)$ ]] && return 0 590 | 591 | __vagrant_complete --disable-http --domain --http \ 592 | --https --name --ssh --ssh-no-password \ 593 | --ssh-once --ssh-port 594 | 595 | return 0 596 | ;; 597 | 598 | snapshot) 599 | if (( __VAGRANT_STATIC_COMPLETION == 1 )); then 600 | readarray -t COMPREPLY < <(compgen -W "${__VAGRANT_SNAPSHOT_COMMANDS[*]}" -- "$cur") 601 | return 0 602 | fi 603 | 604 | # get snapshot commands only if they are not already cached 605 | [[ -z $__vagrant_snapshot_commands ]] && { 606 | __vagrant_snapshot_commands=$(__vagrant_get_subcommands snapshot) || return 1 607 | } 608 | 609 | readarray -t COMPREPLY < <(compgen -W "$__vagrant_snapshot_commands" -- "$cur") 610 | 611 | return 0 612 | ;; 613 | 614 | up) 615 | if [[ $prev = --provider ]]; then 616 | __vagrant_complete_providers 617 | return $? 618 | elif [[ $prev = --provision-with ]]; then 619 | __vagrant_complete_provisioners 620 | return $? 621 | fi 622 | 623 | local not_running='' up_options='' 624 | 625 | up_options=$(__vagrant_list_options --destroy-on-error --install-provider --no-destroy-on-error --no-install-provider --no-parallel --no-provision --parallel --provider --provision --provision-with) 626 | not_running=$(__vagrant_get_not_running) || return 1 627 | 628 | readarray -t COMPREPLY < <(compgen -W "$up_options $not_running" -- "$cur") 629 | 630 | return 0 631 | ;; 632 | 633 | esac 634 | 635 | elif (( ${#words[@]} == 3 )); then 636 | 637 | case "$action" in 638 | 639 | box) 640 | case "$subaction" in 641 | 642 | add) 643 | case $prev in 644 | --cacert|--cert) 645 | _filedir 646 | return $? 647 | ;; 648 | --capath) 649 | _filedir -d 650 | return $? 651 | ;; 652 | --provider) 653 | __vagrant_complete_providers 654 | return $? 655 | ;; 656 | --box-version|--checksum|--checksum-type|--name) 657 | return 0 658 | ;; 659 | esac 660 | 661 | __vagrant_complete --box-version -c --cacert --capath \ 662 | --cert --checksum --checksum-type \ 663 | --clean -f --force --insecure \ 664 | --location-trusted --name --provider 665 | return $? 666 | ;; 667 | 668 | list) 669 | __vagrant_complete -i --box-info 670 | return $? 671 | ;; 672 | 673 | outdated) 674 | case $prev in 675 | --cacert|--cert) 676 | _filedir 677 | return $? 678 | ;; 679 | --capath) 680 | _filedir -d 681 | return $? 682 | ;; 683 | esac 684 | 685 | __vagrant_complete --cacert --capath --cert --global --insecure 686 | 687 | return $? 688 | ;; 689 | 690 | prune) 691 | case $prev in 692 | --name) 693 | : 694 | ;; 695 | -p|--provider) 696 | __vagrant_complete_providers 697 | return $? 698 | ;; 699 | *) 700 | __vagrant_complete --dry-run -f --force -n --name -p --provider 701 | return $? 702 | ;; 703 | esac 704 | ;; 705 | 706 | remove) 707 | case $prev in 708 | --box-version) 709 | local __vagrant_versions='' 710 | 711 | __vagrant_versions=$(__vagrant_get_versions) || return 1 712 | 713 | readarray -t COMPREPLY < <(compgen -W "$__vagrant_versions" -- "$cur") 714 | 715 | return 0 716 | ;; 717 | --provider) 718 | __vagrant_complete_providers 719 | return $? 720 | ;; 721 | esac 722 | 723 | local remove_options='' 724 | 725 | remove_options=$(__vagrant_list_options --all --box-version -f --force --provider) 726 | ;; 727 | 728 | update) 729 | case $prev in 730 | --box) 731 | : 732 | ;; 733 | --cacert|--cert) 734 | _filedir 735 | return $? 736 | ;; 737 | --capath) 738 | _filedir -d 739 | return $? 740 | ;; 741 | --provider) 742 | __vagrant_complete_providers 743 | return $? 744 | ;; 745 | *) 746 | __vagrant_complete --box --cacert --capath --cert --insecure --provider 747 | return $? 748 | ;; 749 | esac 750 | ;; 751 | 752 | esac 753 | 754 | if [[ $subaction =~ ^(prune|remove|repackage|update)$ ]]; then 755 | local box_list='' 756 | 757 | box_list=$(__vagrant_get_boxes) || return 1 758 | 759 | readarray -t COMPREPLY < <(compgen -W "$remove_options $box_list" -- "$cur") 760 | 761 | return 0 762 | fi 763 | ;; 764 | 765 | plugin) 766 | case "$subaction" in 767 | install) 768 | [[ $prev =~ ^(--entry-point|--plugin-source|--plugin-version)$ ]] && return 0 769 | 770 | __vagrant_complete --entry-point --plugin-prerelease \ 771 | --plugin-clean-sources --plugin-source \ 772 | --plugin-version --verbose 773 | return $? 774 | ;; 775 | uninstall|update) 776 | local plugin_list='' 777 | 778 | plugin_list=$(__vagrant_get_plugins) || return 1 779 | 780 | readarray -t COMPREPLY < <(compgen -W "$plugin_list" -- "$cur") 781 | 782 | return 0 783 | ;; 784 | esac 785 | ;; 786 | 787 | snapshot) 788 | case "$subaction" in 789 | go) 790 | local go_options='' 791 | 792 | go_options=$(__vagrant_list_options -r --reload) 793 | ;; 794 | esac 795 | 796 | if [[ $subaction =~ ^(delete|go)$ ]]; then 797 | local snapshot_list='' 798 | 799 | snapshot_list=$(__vagrant_get_snapshots) || return 1 800 | 801 | readarray -t COMPREPLY < <(compgen -W "$go_options $snapshot_list" -- "$cur") 802 | 803 | return 0 804 | fi 805 | ;; 806 | 807 | esac 808 | 809 | fi 810 | } 811 | 812 | complete -F __vagrant "$vagrant" 813 | 814 | } 815 | 816 | unset vagrant 817 | --------------------------------------------------------------------------------