Skip to content

fix: always create the compdef before r-w-o zshrc - #2084

Merged
kemingy merged 3 commits into
tensorchord:mainfrom
kemingy:fix_gh2083
Feb 9, 2026
Merged

kemingy merged 3 commits into
tensorchord:mainfrom
kemingy:fix_gh2083

Conversation

@kemingy

@kemingy kemingy commented Feb 9, 2026

Copy link
Copy Markdown
Member

- fix gh tensorchord#2083

Signed-off-by: Keming <kemingyang@tensorchord.ai>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in InsertZSHCompleteEntry.
  • Keep .zshrc modification 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 ~/.zshrc fails, 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 makes envd completion fail even though the user can complete setup manually, and it also skips deleteZcompdump() due to the early return. Consider treating .zshrc modification as best-effort: keep the warning (ideally include the actual completion file path) but continue execution (e.g., call deleteZcompdump() 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.

Comment thread pkg/autocomplete/zsh.go Resolved
Comment thread pkg/autocomplete/zsh.go Resolved
Signed-off-by: Keming <kemingyang@tensorchord.ai>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pkg/autocomplete/zsh.go Resolved
Signed-off-by: Keming <kemingyang@tensorchord.ai>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 .zshrc update is still guarded by strings.HasPrefix(path, homeDir). Since path is selected from system site-functions dirs first, this condition will be false on most systems, so .zshrc won’t be updated to source ~/.config/envd/envd.zsh and 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 selected path and only appending zshConfig when 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.

Comment thread pkg/autocomplete/zsh.go Resolved
@kemingy
kemingy merged commit 4ca4fdd into tensorchord:main Feb 9, 2026
17 checks passed
@kemingy
kemingy deleted the fix_gh2083 branch February 9, 2026 04:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: zsh completion warning message is misleading - suggests manual config but actual file is never created

2 participants