-
Notifications
You must be signed in to change notification settings - Fork 2
/
zsh.go
53 lines (47 loc) · 1015 Bytes
/
zsh.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"os"
"text/template"
)
var zshSource = fmt.Sprintf(`
#compdef {{.Bosh}}
autoload -U compinit && compinit
autoload -U bashcompinit && bashcompinit
_bosh_comp() {
local output="$({{.Executable}} complete {{.Debug}} -- ${COMP_WORDS[@]:0:$COMP_CWORD} "${COMP_WORDS[$COMP_CWORD]}")"
COMPREPLY=()
local TMPIFS="$IFS"
IFS=''
while read -r line; do
if [[ -n "$line" ]]; then
COMPREPLY+=("$line")
fi
done <<< "$output"
IFS="$TMPIFS"
}
complete -o nospace -F _bosh_comp {{.Bosh}}
`)
func doZshSource() {
tmpl := template.Must(template.New("bash_source").Parse(zshSource))
me, err := os.Executable()
debug := ""
if opts.Debug {
debug = "--debug"
}
if err != nil {
panic("Could not determine executable location")
}
err = tmpl.Execute(os.Stdout, struct {
Executable string
Bosh string
Debug string
}{
Executable: me,
Bosh: "bosh",
Debug: debug,
})
if err != nil {
panic("Could not render source template for zsh")
}
}