Browse code

vagrant plugin autocompletion - initial version

Fedyashev Nikita authored on 15/11/2010 at 19:45:04
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,139 @@
0
+#compdef vagrant 
1
+#autoload
2
+
3
+# vagrant zsh completion, based on homebrew completion
4
+
5
+__task_list ()
6
+{
7
+  local expl
8
+  declare -a tasks
9
+
10
+  tasks=(box destroy halt init package provision reload resume ssh ssh_config status suspend up version)
11
+
12
+  _wanted tasks expl 'help' compadd $tasks
13
+}
14
+
15
+__box_list ()
16
+{
17
+  _wanted application expl 'hxlp' compadd $(command ls -1 $HOME/.vagrant/boxes 2>/dev/null| sed -e 's/ /\\ /g')
18
+}
19
+
20
+__vagrant-box ()
21
+{
22
+ local curcontext="$curcontext" state line
23
+        typeset -A opt_args
24
+
25
+        _arguments -C \
26
+		':command:->command' \
27
+		'*::options:->options'
28
+
29
+        case $state in
30
+                (command)
31
+
32
+                       # local -a subcommands
33
+                       # subcommands=(
34
+                       #         'start:Start a new release branch'
35
+                       #         'finish:Finish a release branche.'
36
+                       #         'list:List all your release branches. (Alias to `git flow release`)'
37
+                       # )
38
+                       # _describe -t commands 'git flow release' subcommands
39
+                       # _arguments \
40
+                       # -v'[Verbose (more) output]'
41
+       _describe -t commands "gem subcommand" _box_arguments
42
+       return
43
+                ;;
44
+
45
+                (options)
46
+                        case $line[1] in
47
+
48
+                                (repackage)
49
+				       _arguments \
50
+						-F'[Fetch from origin before performing finish]' \
51
+						-r'[Rebase instead of merge]'\
52
+							':feature:__box_list' 
53
+
54
+
55
+
56
+                                ;;
57
+                        esac
58
+                ;;
59
+         esac
60
+
61
+}
62
+
63
+local -a _1st_arguments
64
+_1st_arguments=(
65
+  'box:Box commands'
66
+  'destroy:Destroys the vagrant environment'
67
+  'halt:Halts the currently running vagrant environment'
68
+  'help:[TASK] Describe available tasks or one specific task'
69
+  'init:[box_name] [box_url] Initializes current folder for Vagrant usage'
70
+  'package:Packages a vagrant environment for distribution'
71
+  'provision:Run the provisioner'
72
+  'reload:Reload the vagrant environment'
73
+  'resume:Resumes a suspend vagrant environment'
74
+  'ssh:SSH into the currently running environment'
75
+  'ssh_config:outputs .ssh/config valid syntax for connecting to this environment via ssh.'
76
+  'status:Shows the status of the current Vagrant environment.'
77
+  'suspend:Suspends the currently running vagrant environment'
78
+  'up:Creates the vagrant environment'
79
+  'version:Prints the Vagrant version information'
80
+)
81
+
82
+local -a _box_arguments
83
+_box_arguments=(
84
+  'add:NAME URI Add a box to the system'
85
+  'help:COMMAND Describe subcommands or one specific subcommand'
86
+  'list:Lists all installed boxes'
87
+  'remove:NAME Remove a box from the system'
88
+  'repackage:NAME Repackage an installed box into a `.box` file.'
89
+)
90
+
91
+local expl
92
+local -a boxes installed_boxes
93
+
94
+#_arguments \
95
+#  '(-v --version)'{-v,--version}'[show version]' \
96
+#  '(-h --help)'{-h,--help}'[show help]' \
97
+#  '*:: :->subcmds' && return 0
98
+        local curcontext="$curcontext" state line
99
+        typeset -A opt_args
100
+
101
+  _arguments -C \
102
+        ':command:->command' \
103
+        '*::options:->options'
104
+
105
+
106
+
107
+
108
+#echo $state
109
+#echo -e "\n\n\n\n"
110
+#echo $line[1]
111
+
112
+case $state in
113
+
114
+  (command)
115
+
116
+	  _describe -t commands "gem subcommand" _1st_arguments
117
+	  return
118
+  ;;
119
+
120
+  (options)
121
+
122
+    case $line[1] in
123
+
124
+      (help)
125
+	       _arguments \
126
+			-F'[Fetch from origin before performing finish]' \
127
+			-r'[Rebase instead of merge]'\
128
+				':feature:__task_list' 
129
+
130
+      ;;
131
+
132
+      (box)
133
+
134
+        __vagrant-box
135
+      ;;
136
+    esac
137
+  ;;
138
+esac
0 139
new file mode 100644
... ...
@@ -0,0 +1,3 @@
0
+fpath=($ZSH/plugins/vagrant $fpath)
1
+autoload -U compinit
2
+compinit -i