_vagrant 3.79 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
    'connect:Connects to a remotely shared Vagrant environment'
10
    'destroy:Destroys the vagrant environment'
11
12
    'docker-logs:Outputs the logs from the Docker container'
    'docker-run:Run a one-off command in the context of a container'
13
    'global-status:Reports the status of all active Vagrant environments on the system'
14
    'halt:Halts the currently running vagrant environment'
15
    'help:Shows the help for a subcommand'
16
    'init:[box_name] [box_url] Initializes current folder for Vagrant usage'
17
    'list-commands:Outputs all available Vagrant subcommands, even non-primary ones'
18
    'login:Authenticates against a Vagrant Cloud server to access protected boxes'
19
    'package:Packages a vagrant environment for distribution'
Justin Clayton's avatar
Justin Clayton committed
20
    'plugin:Plugin commands'
21
    'provision:Run the provisioner'
22
23
    'push:Deploys code in this environment to a configured destination'
    'rdp:Connects to machine via RDP'
24
25
    'reload:Reload the vagrant environment'
    'resume:Resumes a suspend vagrant environment'
26
27
28
    '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'
29
    'ssh:SSH into the currently running environment'
30
    'ssh-config:Outputs .ssh/config valid syntax for connecting to this environment via ssh'
31
    'status:Shows the status of the current Vagrant environment'
32
33
    'suspend:Suspends the currently running vagrant environment'
    'up:Creates the vagrant environment'
34
    'version:Prints current and latest Vagrant version'
Justin Clayton's avatar
Justin Clayton committed
35
36
    '--help:[TASK] Describe available tasks or one specific task'
    '--version:Prints the Vagrant version information'
37
38
39
40
)

local -a _box_arguments
_box_arguments=(
41
42
    'add:ADDRESS Adds a box to the system'
    'help:COMMAND List subcommands'
43
    'list:Lists all installed boxes'
44
45
46
47
    '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'
48
)
49
50
51

__task_list ()
{
52
53
    local expl
    declare -a tasks
54

55
    tasks=(box destroy halt init package provision reload resume ssh ssh_config status suspend up version)
56

57
    _wanted tasks expl 'help' compadd $tasks
58
59
60
61
}

__box_list ()
{
62
    _wanted application expl 'command' compadd $(command vagrant box list | sed -e 's/ /\\ /g')
63
64
}

65
66
__vm_list ()
{
67
    _wanted application expl 'command' compadd $(command grep Vagrantfile -oe '^[^#]*\.vm\.define *[:"]\([a-zA-Z0-9_-]\+\)' 2>/dev/null | awk '{print substr($2, 2)}')
68
    _wanted application expl 'command' compadd $(command ls .vagrant/machines/ 2>/dev/null)
69
70
}

71
72
__vagrant-box ()
{
73
74
    local curcontext="$curcontext" state line
    typeset -A opt_args
75

76
77
78
    _arguments -C \
        ':command:->command' \
        '*::options:->options'
79

80
81
82
83
84
85
86
87
88
   case $state in
       (command)
           _describe -t commands "gem subcommand" _box_arguments
           return
       ;;

       (options)
           case $line[1] in
               (repackage|remove)
89
                   _arguments ':feature:__box_list'
90
91
92
93
               ;;
           esac
       ;;
    esac
94
95
96
}


97

98
99
100
101

local expl
local -a boxes installed_boxes

102
103
local curcontext="$curcontext" state line
typeset -A opt_args
104

105
106
107
_arguments -C \
    ':command:->command' \
    '*::options:->options'
108
109
110

case $state in
  (command)
111
112
      _describe -t commands "gem subcommand" _1st_arguments
      return
113
114
115
116
117
  ;;

  (options)
    case $line[1] in
      (help)
118
         _arguments ':feature:__task_list'
119
120
121
      ;;

      (box)
122
          __vagrant-box
123
      ;;
124
      (up|provision|package|destroy|reload|ssh|ssh-config|halt|resume|status)
125
      _arguments ':feature:__vm_list'
126
127
128
    esac
  ;;
esac