aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/posener/complete/cmd/install/zsh.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/posener/complete/cmd/install/zsh.go')
-rw-r--r--vendor/github.com/posener/complete/cmd/install/zsh.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/vendor/github.com/posener/complete/cmd/install/zsh.go b/vendor/github.com/posener/complete/cmd/install/zsh.go
new file mode 100644
index 0000000..a625f53
--- /dev/null
+++ b/vendor/github.com/posener/complete/cmd/install/zsh.go
@@ -0,0 +1,39 @@
1package install
2
3import "fmt"
4
5// (un)install in zsh
6// basically adds/remove from .zshrc:
7//
8// autoload -U +X bashcompinit && bashcompinit"
9// complete -C </path/to/completion/command> <command>
10type zsh struct {
11 rc string
12}
13
14func (z zsh) Install(cmd, bin string) error {
15 completeCmd := z.cmd(cmd, bin)
16 if lineInFile(z.rc, completeCmd) {
17 return fmt.Errorf("already installed in %s", z.rc)
18 }
19
20 bashCompInit := "autoload -U +X bashcompinit && bashcompinit"
21 if !lineInFile(z.rc, bashCompInit) {
22 completeCmd = bashCompInit + "\n" + completeCmd
23 }
24
25 return appendToFile(z.rc, completeCmd)
26}
27
28func (z zsh) Uninstall(cmd, bin string) error {
29 completeCmd := z.cmd(cmd, bin)
30 if !lineInFile(z.rc, completeCmd) {
31 return fmt.Errorf("does not installed in %s", z.rc)
32 }
33
34 return removeFromFile(z.rc, completeCmd)
35}
36
37func (zsh) cmd(cmd, bin string) string {
38 return fmt.Sprintf("complete -o nospace -C %s %s", bin, cmd)
39}