diff options
| author | Eyal Posener <[email protected]> | 2017-05-13 11:03:22 +0300 |
|---|---|---|
| committer | Eyal Posener <[email protected]> | 2017-05-13 11:06:15 +0300 |
| commit | 3776c7286e833a6e77db93979c7c1fd01ec8d5fd (patch) | |
| tree | 9cc5ed9f3c11220631d24cde877d4b94fc6e11dc /cmd/install/zsh.go | |
| parent | c7377ba2de5df7097776c07f1ca68ca0fc8ee90e (diff) | |
cmd/install: add support for zsh
Fixes: #9
Diffstat (limited to 'cmd/install/zsh.go')
| -rw-r--r-- | cmd/install/zsh.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/cmd/install/zsh.go b/cmd/install/zsh.go new file mode 100644 index 0000000..9ece779 --- /dev/null +++ b/cmd/install/zsh.go @@ -0,0 +1,39 @@ +package install + +import "fmt" + +// (un)install in zsh +// basically adds/remove from .zshrc: +// +// autoload -U +X bashcompinit && bashcompinit" +// complete -C </path/to/completion/command> <command> +type zsh struct { + rc string +} + +func (z zsh) Install(cmd, bin string) error { + completeCmd := z.cmd(cmd, bin) + if lineInFile(z.rc, completeCmd) { + return fmt.Errorf("already installed in %s", z.rc) + } + + bashCompInit := "autoload -U +X bashcompinit && bashcompinit" + if !lineInFile(z.rc, bashCompInit) { + completeCmd = bashCompInit + "\n" + completeCmd + } + + return appendToFile(z.rc, completeCmd) +} + +func (z zsh) Uninstall(cmd, bin string) error { + completeCmd := z.cmd(cmd, bin) + if !lineInFile(z.rc, completeCmd) { + return fmt.Errorf("does not installed in %s", z.rc) + } + + return removeFromFile(z.rc, completeCmd) +} + +func (zsh) cmd(cmd, bin string) string { + return fmt.Sprintf("complete -C %s %s", bin, cmd) +} |
