_vagrant 3.84 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
    'snapshot:Manage snapshots with the guest machine'
30
    'ssh:SSH into the currently running environment'
31
    'ssh-config:Outputs .ssh/config valid syntax for connecting to this environment via ssh'
32
    'status:Shows the status of the current Vagrant environment'
33
34
    'suspend:Suspends the currently running vagrant environment'
    'up:Creates the vagrant environment'
35
    'version:Prints current and latest Vagrant version'
Justin Clayton's avatar
Justin Clayton committed
36
37
    '--help:[TASK] Describe available tasks or one specific task'
    '--version:Prints the Vagrant version information'
38
39
40
41
)

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

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

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

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

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

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

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

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

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

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


98

99
100
101
102

local expl
local -a boxes installed_boxes

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

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

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

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

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