_vagrant 3.91 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
    'suspend:Suspends the currently running vagrant environment'
Grant Regimbal's avatar
Grant Regimbal committed
34
    'snapshot:Used to manage snapshots with the guest machine'
35
    'up:Creates the vagrant environment'
36
    'version:Prints current and latest Vagrant version'
Justin Clayton's avatar
Justin Clayton committed
37
38
    '--help:[TASK] Describe available tasks or one specific task'
    '--version:Prints the Vagrant version information'
39
40
41
42
)

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

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

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

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

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

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

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

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

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

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


99

100
101
102
103

local expl
local -a boxes installed_boxes

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

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

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

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

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