@@ -83,7 +83,7 @@ func commandToCompletions(name string, fullName string, cmd *cmds.Command) *comp
83
83
return parsed
84
84
}
85
85
86
- var bashCompletionTemplate , fishCompletionTemplate * template.Template
86
+ var bashCompletionTemplate , fishCompletionTemplate , zshCompletionTemplate * template.Template
87
87
88
88
func init () {
89
89
commandTemplate := template .Must (template .New ("command" ).Parse (`
@@ -153,6 +153,28 @@ _ipfs() {
153
153
{{ template "command" . }}
154
154
}
155
155
complete -o nosort -o nospace -o default -F _ipfs ipfs
156
+ ` ))
157
+
158
+ zshCompletionTemplate = template .Must (commandTemplate .New ("root" ).Parse (`#!bin/zsh
159
+ autoload bashcompinit
160
+ bashcompinit
161
+ _ipfs_compgen() {
162
+ local oldifs="$IFS"
163
+ IFS=$'\n'
164
+ while read -r line; do
165
+ COMPREPLY+=("$line")
166
+ done < <(compgen "$@")
167
+ IFS="$oldifs"
168
+ }
169
+
170
+ _ipfs() {
171
+ COMPREPLY=()
172
+ local index=1
173
+ local argidx=0
174
+ local word="${COMP_WORDS[COMP_CWORD]}"
175
+ {{ template "command" . }}
176
+ }
177
+ complete -o nosort -o nospace -o default -F _ipfs ipfs
156
178
` ))
157
179
158
180
fishCommandTemplate := template .Must (template .New ("command" ).Parse (`
@@ -221,3 +243,8 @@ func writeFishCompletions(cmd *cmds.Command, out io.Writer) error {
221
243
cmds := commandToCompletions ("ipfs" , "" , cmd )
222
244
return fishCompletionTemplate .Execute (out , cmds )
223
245
}
246
+
247
+ func writeZshCompletions (cmd * cmds.Command , out io.Writer ) error {
248
+ cmds := commandToCompletions ("ipfs" , "" , cmd )
249
+ return zshCompletionTemplate .Execute (out , cmds )
250
+ }
0 commit comments