Merge pull request #11520 from soapy1/zsh-completion
Add zsh completion
This commit is contained in:
commit
7eb55bdecf
@ -14,3 +14,4 @@ for each item will be kept below.
|
||||
starting machines.
|
||||
* `vim` - Contains a `.vim` file for enabling Ruby syntax highlighting
|
||||
for `Vagrantfile`s in `vim`.
|
||||
* `zsh` - Contains a zsh script for improving autocompletion with zsh.
|
||||
|
||||
736
contrib/zsh/_vagrant
Normal file
736
contrib/zsh/_vagrant
Normal file
@ -0,0 +1,736 @@
|
||||
|
||||
#compdef _vagrant vagrant
|
||||
|
||||
# ZSH completion for Vagrant
|
||||
#
|
||||
# To use this completion add this to ~/.zshrc
|
||||
# fpath=(/path/to/this/dir $fpath)
|
||||
# compinit
|
||||
#
|
||||
# For development reload the function after making changes
|
||||
# unfunction _vagrant && autoload -U _vagrant
|
||||
|
||||
|
||||
__box_list ()
|
||||
{
|
||||
_wanted application expl 'command' compadd $(command vagrant box list | awk '{print $1}' )
|
||||
}
|
||||
|
||||
|
||||
__plugin_list ()
|
||||
{
|
||||
_wanted application expl 'command' compadd $(command vagrant plugin list | awk '{print $1}')
|
||||
}
|
||||
|
||||
|
||||
function _vagrant () {
|
||||
|
||||
local -a sub_commands && sub_commands=(
|
||||
'box:manages boxes: installation, removal, etc.'
|
||||
'cloud:manages everything related to Vagrant Cloud'
|
||||
'destroy:stops and deletes all traces of the vagrant machine'
|
||||
'global-status:outputs status Vagrant environments for this user'
|
||||
'halt:stops the vagrant machine'
|
||||
'help:shows the help for a subcommand'
|
||||
'init:initializes a new Vagrant environment by creating a Vagrantfile'
|
||||
'login:'
|
||||
'package:packages a running vagrant environment into a box'
|
||||
'plugin:manages plugins: install, uninstall, update, etc.'
|
||||
'port:displays information about guest port mappings'
|
||||
'powershell:connects to machine via powershell remoting'
|
||||
'provision:provisions the vagrant machine'
|
||||
'push:deploys code in this environment to a configured destination'
|
||||
'rdp:connects to machine via RDP'
|
||||
'reload:restarts vagrant machine, loads new Vagrantfile configuration'
|
||||
'resume:resume a suspended vagrant machine'
|
||||
'snapshot:manages snapshots: saving, restoring, etc.'
|
||||
'ssh:connects to machine via SSH'
|
||||
'ssh-config:outputs OpenSSH valid configuration to connect to the machine'
|
||||
'status:outputs status of the vagrant machine'
|
||||
'suspend:suspends the machine'
|
||||
'up:starts and provisions the vagrant environment'
|
||||
'upload:upload to machine via communicator'
|
||||
'validate:validates the Vagrantfile'
|
||||
'version:prints current and latest Vagrant version'
|
||||
'winrm:executes commands on a machine via WinRM'
|
||||
'winrm-config:outputs WinRM configuration to connect to the machine'
|
||||
)
|
||||
|
||||
local -a cloud_arguments && cloud_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a destroy_arguments && destroy_arguments=(
|
||||
'--(no-)parallel=[Enable or disable parallelism if provider supports it (automatically enables force)]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a global_status_arguments && global_status_arguments=(
|
||||
'--prune=[Prune invalid entries.]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a halt_arguments && halt_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a help_arguments && help_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a init_arguments && init_arguments=(
|
||||
'--box-version=[Version of the box to add]'
|
||||
'--output=[Output path for the box. _ for stdout]'
|
||||
'--template=[Path to custom Vagrantfile template]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a login_arguments && login_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a package_arguments && package_arguments=(
|
||||
'--base=[Name of a VM in VirtualBox to package as a base box (VirtualBox Only)]'
|
||||
'--output=[Name of the file to output]'
|
||||
'--include=[Comma separated additional files to package with the box]'
|
||||
'--vagrantfile=[Vagrantfile to package with the box]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a port_arguments && port_arguments=(
|
||||
'--guest=[Output the host port that maps to the given guest port]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a powershell_arguments && powershell_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a provision_arguments && provision_arguments=(
|
||||
'--provision-with=[Enable only certain provisioners, by type or by name.]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a push_arguments && push_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a rdp_arguments && rdp_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a reload_arguments && reload_arguments=(
|
||||
'--(no-)provision=[Enable or disable provisioning]'
|
||||
'--provision-with=[Enable only certain provisioners, by type or by name.]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a resume_arguments && resume_arguments=(
|
||||
'--(no-)provision=[Enable or disable provisioning]'
|
||||
'--provision-with=[Enable only certain provisioners, by type or by name.]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a ssh_arguments && ssh_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a ssh_config_arguments && ssh_config_arguments=(
|
||||
'--host=[Name the host for the config]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a status_arguments && status_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a suspend_arguments && suspend_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a up_arguments && up_arguments=(
|
||||
'--(no-)provision=[Enable or disable provisioning]'
|
||||
'--provision-with=[Enable only certain provisioners, by type or by name.]'
|
||||
'--(no-)destroy-on-error=[Destroy machine if any fatal error happens (default to true)]'
|
||||
'--(no-)parallel=[Enable or disable parallelism if provider supports it]'
|
||||
'--provider=[Back the machine with a specific provider]'
|
||||
'--(no-)install-provider=[If possible, install the provider if it isnt installed]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a upload_arguments && upload_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a validate_arguments && validate_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a version_arguments && version_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a winrm_arguments && winrm_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a winrm_config_arguments && winrm_config_arguments=(
|
||||
'--host=[Name the host for the config]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
|
||||
|
||||
_arguments -C ':command:->command' '*::options:->options'
|
||||
|
||||
case $state in
|
||||
(command)
|
||||
_describe -t commands 'command' sub_commands
|
||||
return
|
||||
;;
|
||||
|
||||
(options)
|
||||
case $line[1] in
|
||||
box)
|
||||
__vagrant-box ;;
|
||||
cloud)
|
||||
_arguments -s -S : $cloud_arguments ;;
|
||||
destroy)
|
||||
_arguments -s -S : $destroy_arguments ;;
|
||||
global-status)
|
||||
_arguments -s -S : $global_status_arguments ;;
|
||||
halt)
|
||||
_arguments -s -S : $halt_arguments ;;
|
||||
help)
|
||||
_arguments -s -S : $help_arguments ;;
|
||||
init)
|
||||
_arguments -s -S : $init_arguments ;;
|
||||
login)
|
||||
_arguments -s -S : $login_arguments ;;
|
||||
package)
|
||||
_arguments -s -S : $package_arguments ;;
|
||||
plugin)
|
||||
__vagrant-plugin ;;
|
||||
port)
|
||||
_arguments -s -S : $port_arguments ;;
|
||||
powershell)
|
||||
_arguments -s -S : $powershell_arguments ;;
|
||||
provision)
|
||||
_arguments -s -S : $provision_arguments ;;
|
||||
push)
|
||||
_arguments -s -S : $push_arguments ;;
|
||||
rdp)
|
||||
_arguments -s -S : $rdp_arguments ;;
|
||||
reload)
|
||||
_arguments -s -S : $reload_arguments ;;
|
||||
resume)
|
||||
_arguments -s -S : $resume_arguments ;;
|
||||
snapshot)
|
||||
__vagrant-snapshot ;;
|
||||
ssh)
|
||||
_arguments -s -S : $ssh_arguments ;;
|
||||
ssh-config)
|
||||
_arguments -s -S : $ssh_config_arguments ;;
|
||||
status)
|
||||
_arguments -s -S : $status_arguments ;;
|
||||
suspend)
|
||||
_arguments -s -S : $suspend_arguments ;;
|
||||
up)
|
||||
_arguments -s -S : $up_arguments ;;
|
||||
upload)
|
||||
_arguments -s -S : $upload_arguments ;;
|
||||
validate)
|
||||
_arguments -s -S : $validate_arguments ;;
|
||||
version)
|
||||
_arguments -s -S : $version_arguments ;;
|
||||
winrm)
|
||||
_arguments -s -S : $winrm_arguments ;;
|
||||
winrm-config)
|
||||
_arguments -s -S : $winrm_config_arguments ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
}
|
||||
|
||||
function __vagrant-box () {
|
||||
|
||||
local -a sub_commands && sub_commands=(
|
||||
'add:add'
|
||||
'list:list'
|
||||
'outdated:outdated'
|
||||
'prune:prune'
|
||||
'remove:remove'
|
||||
'repackage:repackage'
|
||||
'update:update'
|
||||
)
|
||||
|
||||
local -a add_arguments && add_arguments=(
|
||||
'--insecure=[Do not validate SSL certificates]'
|
||||
'--cacert=[CA certificate for SSL download]'
|
||||
'--capath=[CA certificate directory for SSL download]'
|
||||
'--cert=[A client SSL cert, if needed]'
|
||||
'--location-trusted=[Trust Location header from HTTP redirects and use the same credentials for subsequent urls as for the initial one]'
|
||||
'--provider=[Provider the box should satisfy]'
|
||||
'--box-version=[Constrain version of the added box]'
|
||||
'--checksum=[Checksum for the box]'
|
||||
'--checksum-type=[Checksum type (md5, sha1, sha256)]'
|
||||
'--name=[Name of the box]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a list_arguments && list_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a outdated_arguments && outdated_arguments=(
|
||||
'--global=[Check all boxes installed]'
|
||||
'--insecure=[Do not validate SSL certificates]'
|
||||
'--cacert=[CA certificate for SSL download]'
|
||||
'--capath=[CA certificate directory for SSL download]'
|
||||
'--cert=[A client SSL cert, if needed]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a prune_arguments && prune_arguments=(
|
||||
'--name=[The specific box name to check for outdated versions.]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a remove_arguments && remove_arguments=(
|
||||
'--provider=[The specific provider type for the box to remove]'
|
||||
'--box-version=[The specific version of the box to remove]'
|
||||
'--all=[Remove all available versions of the box]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a repackage_arguments && repackage_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a update_arguments && update_arguments=(
|
||||
'--box=[__box flag.]'
|
||||
'--box=[Update a specific box]'
|
||||
'--provider=[Update box with specific provider]'
|
||||
'--insecure=[Do not validate SSL certificates]'
|
||||
'--cacert=[CA certificate for SSL download]'
|
||||
'--capath=[CA certificate directory for SSL download]'
|
||||
'--cert=[A client SSL cert, if needed]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
|
||||
|
||||
_arguments -C ':command:->command' '*::options:->options'
|
||||
|
||||
case $state in
|
||||
(command)
|
||||
_describe -t commands 'command' sub_commands
|
||||
return
|
||||
;;
|
||||
|
||||
(options)
|
||||
case $line[1] in
|
||||
add)
|
||||
_arguments -s -S : $add_arguments ;;
|
||||
list)
|
||||
_arguments -s -S : $list_arguments ;;
|
||||
outdated)
|
||||
_arguments -s -S : $outdated_arguments ;;
|
||||
prune)
|
||||
_arguments -s -S : $prune_arguments ;;
|
||||
remove)
|
||||
_arguments -s -S : $remove_arguments ':feature:__box_list' ;;
|
||||
repackage)
|
||||
_arguments -s -S : $repackage_arguments ':feature:__box_list' ;;
|
||||
update)
|
||||
_arguments -s -S : $update_arguments ':feature:__box_list' ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
}
|
||||
|
||||
function __vagrant-snapshot () {
|
||||
|
||||
local -a sub_commands && sub_commands=(
|
||||
'delete:delete'
|
||||
'list:list'
|
||||
'pop:pop'
|
||||
'push:push'
|
||||
'restore:restore'
|
||||
'save:save'
|
||||
)
|
||||
|
||||
local -a delete_arguments && delete_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a list_arguments && list_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a pop_arguments && pop_arguments=(
|
||||
'--(no-)provision=[Enable or disable provisioning]'
|
||||
'--provision-with=[Enable only certain provisioners, by type or by name.]'
|
||||
'--no-delete=[Dont delete the snapshot after the restore]'
|
||||
'--no-start=[Dont start the snapshot after the restore]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a push_arguments && push_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a restore_arguments && restore_arguments=(
|
||||
'--(no-)provision=[Enable or disable provisioning]'
|
||||
'--provision-with=[Enable only certain provisioners, by type or by name.]'
|
||||
'--no-start=[Dont start the snapshot after the restore]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a save_arguments && save_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
|
||||
|
||||
_arguments -C ':command:->command' '*::options:->options'
|
||||
|
||||
case $state in
|
||||
(command)
|
||||
_describe -t commands 'command' sub_commands
|
||||
return
|
||||
;;
|
||||
|
||||
(options)
|
||||
case $line[1] in
|
||||
delete)
|
||||
_arguments -s -S : $delete_arguments ;;
|
||||
list)
|
||||
_arguments -s -S : $list_arguments ;;
|
||||
pop)
|
||||
_arguments -s -S : $pop_arguments ;;
|
||||
push)
|
||||
_arguments -s -S : $push_arguments ;;
|
||||
restore)
|
||||
_arguments -s -S : $restore_arguments ;;
|
||||
save)
|
||||
_arguments -s -S : $save_arguments ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
}
|
||||
|
||||
function __vagrant-plugin () {
|
||||
|
||||
local -a sub_commands && sub_commands=(
|
||||
'expunge:expunge'
|
||||
'install:install'
|
||||
'license:license'
|
||||
'list:list'
|
||||
'repair:repair'
|
||||
'uninstall:uninstall'
|
||||
'update:update'
|
||||
)
|
||||
|
||||
local -a expunge_arguments && expunge_arguments=(
|
||||
'--force=[Do not prompt for confirmation]'
|
||||
'--local=[Include plugins from local project for expunge]'
|
||||
'--local-only=[Only expunge local project plugins]'
|
||||
'--global-only=[Only expunge global plugins]'
|
||||
'--reinstall=[Reinstall current plugins after expunge]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a install_arguments && install_arguments=(
|
||||
'--entry-point=[The name of the entry point file for loading the plugin.]'
|
||||
'--plugin-clean-sources=[Remove all plugin sources defined so far (including defaults)]'
|
||||
'--plugin-source=[__plugin_source PLUGIN_SOURCE]'
|
||||
'--plugin-version=[__plugin_version PLUGIN_VERSION]'
|
||||
'--local=[Install plugin for local project only]'
|
||||
'--verbose=[Enable verbose output for plugin installation]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a license_arguments && license_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a list_arguments && list_arguments=(
|
||||
'--local=[Include local project plugins]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a repair_arguments && repair_arguments=(
|
||||
'--local=[Repair plugins in local project]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a uninstall_arguments && uninstall_arguments=(
|
||||
'--local=[Remove plugin from local project]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a update_arguments && update_arguments=(
|
||||
'--local=[Update plugin in local project]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
|
||||
|
||||
_arguments -C ':command:->command' '*::options:->options'
|
||||
|
||||
case $state in
|
||||
(command)
|
||||
_describe -t commands 'command' sub_commands
|
||||
return
|
||||
;;
|
||||
|
||||
(options)
|
||||
case $line[1] in
|
||||
expunge)
|
||||
_arguments -s -S : $expunge_arguments ;;
|
||||
install)
|
||||
_arguments -s -S : $install_arguments ;;
|
||||
license)
|
||||
_arguments -s -S : $license_arguments ;;
|
||||
list)
|
||||
_arguments -s -S : $list_arguments ;;
|
||||
repair)
|
||||
_arguments -s -S : $repair_arguments ':feature:__plugin_list' ;;
|
||||
uninstall)
|
||||
_arguments -s -S : $uninstall_arguments ':feature:__plugin_list' ;;
|
||||
update)
|
||||
_arguments -s -S : $update_arguments ':feature:__plugin_list' ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
}
|
||||
166
contrib/zsh/generate_zsh_completion.rb
Normal file
166
contrib/zsh/generate_zsh_completion.rb
Normal file
@ -0,0 +1,166 @@
|
||||
require 'open3'
|
||||
|
||||
HEAD = """
|
||||
#compdef _vagrant vagrant
|
||||
|
||||
# ZSH completion for Vagrant
|
||||
#
|
||||
# To use this completion add this to ~/.zshrc
|
||||
# fpath=(/path/to/this/dir $fpath)
|
||||
# compinit
|
||||
#
|
||||
# For development reload the function after making changes
|
||||
# unfunction _vagrant && autoload -U _vagrant
|
||||
"""
|
||||
|
||||
BOX_LIST_FUNCTION = """
|
||||
__box_list ()
|
||||
{
|
||||
_wanted application expl 'command' compadd $(command vagrant box list | awk '{print $1}' )
|
||||
}
|
||||
"""
|
||||
|
||||
PLUGIN_LIST_FUNCTION = """
|
||||
__plugin_list ()
|
||||
{
|
||||
_wanted application expl 'command' compadd $(command vagrant plugin list | awk '{print $1}')
|
||||
}
|
||||
"""
|
||||
|
||||
ADD_FEATURE_FLAGS = ["remove", "repackage", "update", "repair", "uninstall"]
|
||||
VAGRANT_COMMAND = "vagrant"
|
||||
|
||||
FLAG_REGEX = /--(\S)*/
|
||||
CMDS_REGEX = /^(\s){1,}(\w)(\S)*/
|
||||
|
||||
def make_string_script_safe(s)
|
||||
s.gsub("[","(").gsub("]",")").gsub("-","_").gsub("'", "")
|
||||
end
|
||||
|
||||
def remove_square_brakets(s)
|
||||
s.gsub("[","(").gsub("]",")")
|
||||
end
|
||||
|
||||
def format_flags(group_name, flags)
|
||||
group_name = make_string_script_safe(group_name)
|
||||
opts_str = "local -a #{group_name} && #{group_name}=(\n"
|
||||
flags.each do |flag, desc|
|
||||
opts_str = opts_str + " '#{remove_square_brakets(flag)}=[#{make_string_script_safe(desc)}]'\n"
|
||||
end
|
||||
opts_str + ")"
|
||||
end
|
||||
|
||||
def format_subcommand(group_name, cmds)
|
||||
opts_str = "local -a #{group_name} && #{group_name}=(\n"
|
||||
cmds.each do |cmd, desc|
|
||||
opts_str = opts_str + " '#{cmd}:#{desc}'\n"
|
||||
end
|
||||
opts_str + ")"
|
||||
end
|
||||
|
||||
def format_case(group_name, cmds, cmd_list, feature_string)
|
||||
case_str = """case $state in
|
||||
(command)
|
||||
_describe -t commands 'command' #{group_name}
|
||||
return
|
||||
;;
|
||||
|
||||
(options)
|
||||
case $line[1] in
|
||||
"""
|
||||
|
||||
cmds.each do |cmd, desc|
|
||||
if cmd_list.include?(cmd)
|
||||
case_append = """ #{cmd})
|
||||
_arguments -s -S : $#{make_string_script_safe(cmd)}_arguments #{feature_string if ADD_FEATURE_FLAGS.include?(cmd)} ;;
|
||||
"""
|
||||
else
|
||||
case_append = """ #{cmd})
|
||||
__vagrant-#{cmd} ;;
|
||||
"""
|
||||
end
|
||||
case_str = case_str + case_append
|
||||
end
|
||||
|
||||
case_str = case_str + """esac
|
||||
;;
|
||||
esac
|
||||
"""
|
||||
end
|
||||
|
||||
def extract_flags(top_level_commands)
|
||||
flags = top_level_commands.map { |c| [c.match(FLAG_REGEX)[0], c.split(" ")[-1].strip] if c.strip.start_with?("--") }.compact
|
||||
end
|
||||
|
||||
def extract_subcommand(top_level_commands)
|
||||
cmds = top_level_commands.map { |c| [c.match(CMDS_REGEX)[0].strip, c.split(" ")[-1].strip] if c.match(CMDS_REGEX) }.compact
|
||||
end
|
||||
|
||||
def get_top_level_commands(root_command, cmd_list)
|
||||
stdout, stderr, status = Open3.capture3("vagrant #{root_command} -h")
|
||||
top_level_commands = stdout.split("\n")
|
||||
|
||||
root_subcommand = extract_subcommand(top_level_commands)
|
||||
commands = format_subcommand("sub_commands", root_subcommand)
|
||||
if root_command == "box"
|
||||
feature_string = "':feature:__box_list'"
|
||||
elsif root_command == "plugin"
|
||||
feature_string = "':feature:__plugin_list'"
|
||||
else
|
||||
feature_string = ""
|
||||
end
|
||||
case_string = format_case("sub_commands", root_subcommand, cmd_list, feature_string)
|
||||
|
||||
flags_def = ""
|
||||
root_subcommand.each do |cmd, desc|
|
||||
next if !cmd_list.include?(cmd)
|
||||
stdout, stderr, status = Open3.capture3("vagrant #{root_command} #{cmd} -h")
|
||||
cmd_help = stdout.split("\n")
|
||||
flags_def = flags_def + format_flags("#{cmd}_arguments", extract_flags(cmd_help)) + "\n\n"
|
||||
end
|
||||
|
||||
return commands, flags_def, case_string
|
||||
end
|
||||
|
||||
def format_script(root_command, subcommands, funciton_name)
|
||||
top_level_commands, top_level_args, state_case = get_top_level_commands(root_command, subcommands)
|
||||
|
||||
script = """
|
||||
function #{funciton_name} () {
|
||||
|
||||
#{top_level_commands}
|
||||
|
||||
#{top_level_args}
|
||||
|
||||
_arguments -C ':command:->command' '*::options:->options'
|
||||
|
||||
#{state_case}
|
||||
}
|
||||
"""
|
||||
end
|
||||
|
||||
def generate_script
|
||||
subcommand_list = {
|
||||
"" => ["cloud", "destroy", "global-status", "halt", "help", "login", "init", "package", "port", "powershell", "provision", "push", "rdp", "reload", "resume", "ssh", "ssh-config", "status", "suspend", "up", "upload", "validate", "version", "winrm", "winrm-config"],
|
||||
"box" => ["add", "list", "outdated", "prune", "remove", "repackage", "update"],
|
||||
"snapshot" => ["delete", "list", "pop", "push", "restore", "save"],
|
||||
"plugin" => ["install", "expunge", "license", "list", "repair", "uninstall", "update"],
|
||||
}
|
||||
|
||||
script = """#{HEAD}
|
||||
#{BOX_LIST_FUNCTION}
|
||||
#{PLUGIN_LIST_FUNCTION}
|
||||
"""
|
||||
|
||||
subcommand_list.each do |cmd, opts|
|
||||
if cmd != ""
|
||||
function_name = "__vagrant-#{cmd}"
|
||||
else
|
||||
function_name = "_vagrant"
|
||||
end
|
||||
script = script + format_script(cmd, opts, function_name)
|
||||
end
|
||||
script
|
||||
end
|
||||
|
||||
puts generate_script
|
||||
Loading…
x
Reference in New Issue
Block a user