Repository navigation
fix: always create the compdef before r-w-o zshrc - #2084
Conversation
kemingy
commented
Feb 9, 2026
- fix gh bug: zsh completion warning message is misleading - suggests manual config but actual file is never created #2083
- fix gh tensorchord#2083 Signed-off-by: Keming <kemingyang@tensorchord.ai>
There was a problem hiding this comment.
Pull request overview
Fixes the zsh autocomplete installation flow so the zsh completion script (envd.zsh) is written before attempting to modify a potentially read-only ~/.zshrc, addressing the misleading warning described in #2083.
Changes:
- Generate and write the zsh completion file (
envd.zsh) earlier inInsertZSHCompleteEntry. - Keep
.zshrcmodification as a later step, after the completion file is created.
Comments suppressed due to low confidence (1)
pkg/autocomplete/zsh.go:123
- When opening/writing
~/.zshrcfails, the function logs a warning with manual instructions but then returns the underlying error. Since the completion file is now already written earlier in this function, returning an error here makesenvd completionfail even though the user can complete setup manually, and it also skipsdeleteZcompdump()due to the early return. Consider treating.zshrcmodification as best-effort: keep the warning (ideally include the actual completion file path) but continue execution (e.g., calldeleteZcompdump()and return nil).
zshFile, err := os.OpenFile(fmt.Sprintf("%s/.zshrc", homeDir), os.O_RDWR|os.O_APPEND|os.O_CREATE, 0660)
if err != nil {
log.L.Warnf("unable to open the `~/.zshrc`, please add the following lines into `~/.zshrc` to get the envd zsh completion:\n"+
" %s\n", zshConfig)
return err
}
defer zshFile.Close()
_, err = fmt.Fprintf(zshFile, "%s\n", zshConfig)
if err != nil {
log.L.Warnf("unable to write the `~/.zshrc`, please add the following lines into `~/.zshrc` to get the envd zsh completion:\n"+
" %s\n", zshConfig)
return err
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Keming <kemingyang@tensorchord.ai>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Keming <kemingyang@tensorchord.ai>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
pkg/autocomplete/zsh.go:116
- The completion file is now always written to
compdefPath(envd config dir), but the.zshrcupdate is still guarded bystrings.HasPrefix(path, homeDir). Sincepathis selected from systemsite-functionsdirs first, this condition will be false on most systems, so.zshrcwon’t be updated to source~/.config/envd/envd.zshand the newly created completion file won’t be loaded. Consider basing the guard on the actual output path (compdefPath/DefaultConfigDir) or continuing to write to the selectedpathand only appendingzshConfigwhen installing into the user config dir; also make the duplicate-prevention check use the same target path.
if strings.HasPrefix(path, homeDir) && !pathExists {
// write when the path does not exist to prevent duplicate writing during updates.
zshFile, err := os.OpenFile(fmt.Sprintf("%s/.zshrc", homeDir), os.O_RDWR|os.O_APPEND|os.O_CREATE, 0660)
if err != nil {
log.L.Warnf("unable to open the `~/.zshrc`, please add the following lines into `~/.zshrc` to get the envd zsh completion:\n"+
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.