_vagrant 4.12 KB
Newer Older
1
#compdef vagrant
2
3
#autoload

4
5
6
7
8
# vagrant zsh completion

local -a _1st_arguments
_1st_arguments=(
    '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
13
    'docker-logs:Outputs the logs from the Docker container'
    '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'
Justin Clayton's avatar
Justin Clayton committed
21
    'plugin:Plugin commands'
22
    'port:Displays information about guest port mappings'
23
    'provision:Run the provisioner'
24
25
    'push:Deploys code in this environment to a configured destination'
    'rdp:Connects to machine via RDP'
26
    'reload:Reload the vagrant environment'
27
    'resume:Resumes a suspended vagrant environment'
28
29
30
    'rsync:Syncs rsync synced folders to remote machine'
    'rsync-auto:Syncs rsync synced folders automatically when files change'
    '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'
Grant Regimbal's avatar
Grant Regimbal committed
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'
Justin Clayton's avatar
Justin Clayton committed
40
41
    '--help:[TASK] Describe available tasks or one specific task'
    '--version:Prints the Vagrant version information'
42
43
44
45
)

local -a _box_arguments
_box_arguments=(
46
47
    'add:ADDRESS Adds a box to the system'
    'help:COMMAND List subcommands'
48
    'list:Lists all installed boxes'
49
50
51
52
    'outdated:Checks if a box has newer version'
    'remove:NAME Removes a box from the system'
    'repackage:NAME PROVIDER VERSION Repackages an installed box into a `.box` file'
    'update:Updates box to a newer version, if available'
53
)
54
55
56

__task_list ()
{
57
58
    local expl
    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
66
}

__box_list ()
{
67
    _wanted application expl 'command' compadd $(command vagrant box list | sed -e 's/ /\\ /g')
68
69
}

70
71
__vm_list ()
{
72
73
    _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)}')
    _wanted application expl 'command' compadd $(command ls "${VAGRANT_CWD:-.}/.vagrant/machines/" 2>/dev/null)
74
75
}

76
77
__vagrant-box ()
{
78
79
    local curcontext="$curcontext" state line
    typeset -A opt_args
80

81
82
83
    _arguments -C \
        ':command:->command' \
        '*::options:->options'
84

85
86
   case $state in
       (command)
87
           _describe -t commands "vagrant subcommand" _box_arguments
88
89
90
91
92
93
           return
       ;;

       (options)
           case $line[1] in
               (repackage|remove)
94
                   _arguments ':feature:__box_list'
95
96
97
98
               ;;
           esac
       ;;
    esac
99
100
101
}


102

103
104
105
106

local expl
local -a boxes installed_boxes

107
108
local curcontext="$curcontext" state line
typeset -A opt_args
109

110
111
112
_arguments -C \
    ':command:->command' \
    '*::options:->options'
113
114
115

case $state in
  (command)
116
      _describe -t commands "vagrant subcommand" _1st_arguments
117
      return
118
119
120
121
122
  ;;

  (options)
    case $line[1] in
      (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
132
133
    esac
  ;;
esac