From b7a6ebd644973d9fa06fe404d3e66599988ba634 Mon Sep 17 00:00:00 2001 From: Benjamin Cooper Date: Sun, 28 Jun 2020 08:22:44 +0900 Subject: [PATCH 1/2] Add check for autoloading compinit in zsh.go Encountered issue when trying to install autocompletion for terraform on fresh MacOS with default zsh configuration, using their `terraform -install-autocomplete` command. Raised issue on terraform git (https://github.com/hashicorp/terraform/issues/25421) and found it imports this module. Cloned zsh.go and added check for the line that autoloads the zsh compinit. Please review, thanks! --- install/zsh.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/install/zsh.go b/install/zsh.go index cc00c88..ea66a71 100644 --- a/install/zsh.go +++ b/install/zsh.go @@ -6,6 +6,7 @@ import "fmt" // basically adds/remove from .zshrc: // // autoload -U +X bashcompinit && bashcompinit" +// autoload -Uz compinit && compinit // complete -C type zsh struct { rc string @@ -23,9 +24,13 @@ func (z zsh) Install(cmd, bin string) error { completeCmd := z.cmd(cmd, bin) bashCompInit := "autoload -U +X bashcompinit && bashcompinit" + compInit := "autoload -Uz compinit && compinit" if !lineInFile(z.rc, bashCompInit) { completeCmd = bashCompInit + "\n" + completeCmd } + if !lineInFile(z.rc, compInit) { + completeCmd = bashCompInit + "\n" + compInit + "\n" + completeCmd + } return appendFile(z.rc, completeCmd) } From fcba7c8248b814c4d44912ed6ad9079229bffb77 Mon Sep 17 00:00:00 2001 From: Benjamin Cooper Date: Tue, 30 Jun 2020 12:40:37 +0900 Subject: [PATCH 2/2] Update zsh.go Fixed bug in compInit check that would duplicate bashcompinit line in if both bashcompinit and compinit lines are missing from z.rc file. --- install/zsh.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/zsh.go b/install/zsh.go index ea66a71..38f19fc 100644 --- a/install/zsh.go +++ b/install/zsh.go @@ -29,7 +29,7 @@ func (z zsh) Install(cmd, bin string) error { completeCmd = bashCompInit + "\n" + completeCmd } if !lineInFile(z.rc, compInit) { - completeCmd = bashCompInit + "\n" + compInit + "\n" + completeCmd + completeCmd = compInit + "\n" + completeCmd } return appendFile(z.rc, completeCmd)