Skip to content

Commit 4ca4fdd

Browse files
authored
fix: always create the compdef before r-w-o zshrc (#2084)
* fix: always create the compdef before r-w-o zshrc - fix gh #2083 Signed-off-by: Keming <kemingyang@tensorchord.ai> * fix: always use the ~/.config/envd/envd.zsh path Signed-off-by: Keming <kemingyang@tensorchord.ai> * fix: ensure compdef path exist Signed-off-by: Keming <kemingyang@tensorchord.ai> --------- Signed-off-by: Keming <kemingyang@tensorchord.ai>
1 parent 3cac99f commit 4ca4fdd

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

pkg/autocomplete/zsh.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ func InsertZSHCompleteEntry(clicontext *cli.Context) error {
9797
return errors.Wrapf(err, "failed to check if %s exists", path)
9898
}
9999

100+
compEntry, err := ZshCompleteEntry(clicontext)
101+
if err != nil {
102+
return errors.Wrap(err, "Warning: unable to enable zsh-completion")
103+
}
104+
compdefPath, err := fileutil.ConfigFile(filename)
105+
if err != nil {
106+
return errors.Wrapf(err, "failed to get the config path for %s", filename)
107+
}
108+
if err = os.WriteFile(compdefPath, []byte(compEntry), 0644); err != nil {
109+
return errors.Wrapf(err, "failed writing to %s", compdefPath)
110+
}
111+
100112
if strings.HasPrefix(path, homeDir) && !pathExists {
101113
// write when the path does not exist to prevent duplicate writing during updates.
102114
zshFile, err := os.OpenFile(fmt.Sprintf("%s/.zshrc", homeDir), os.O_RDWR|os.O_APPEND|os.O_CREATE, 0660)
@@ -115,15 +127,6 @@ func InsertZSHCompleteEntry(clicontext *cli.Context) error {
115127
}
116128
}
117129

118-
compEntry, err := ZshCompleteEntry(clicontext)
119-
if err != nil {
120-
return errors.Wrapf(err, "Warning: unable to enable zsh-completion")
121-
}
122-
123-
if err = os.WriteFile(path, []byte(compEntry), 0644); err != nil {
124-
return errors.Wrapf(err, "failed writing to %s", path)
125-
}
126-
127130
return deleteZcompdump()
128131
}
129132

0 commit comments

Comments
 (0)