summaryrefslogtreecommitdiff
path: root/cmd/install/zsh.go
diff options
context:
space:
mode:
authorEyal Posener <[email protected]>2017-05-13 11:10:46 +0300
committerGitHub <[email protected]>2017-05-13 11:10:46 +0300
commit758253551ecf81fc5fb107ef8bdad2745d3525fb (patch)
tree49ef787eeb6071d84adb7c8f35051d474351f11f /cmd/install/zsh.go
parentcc2d0e6974a8644191666e9e1e466b06c8bd6cde (diff)
parent87f385425a98490ad44c01e33d16e6a4324696f0 (diff)
Merge pull request #18 from posener/zsh
zsh support
Diffstat (limited to 'cmd/install/zsh.go')
-rw-r--r--cmd/install/zsh.go39
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)
+}