Skip to content

Commit e51c6eb

Browse files
committed
[shell] respect ZDOTDIR for zsh startup files, and copy startup files instead of linking
1 parent dfd5d53 commit e51c6eb

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

internal/impl/shell.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ func initShellBinaryFields(path string) *DevboxShell {
152152
shell.userShellrcPath = rcfilePath(".bashrc")
153153
case "zsh":
154154
shell.name = shZsh
155-
shell.userShellrcPath = rcfilePath(".zshrc")
155+
if zdotdir := os.Getenv("ZDOTDIR"); zdotdir != "" {
156+
shell.userShellrcPath = filepath.Join(os.ExpandEnv(zdotdir), ".zshrc")
157+
} else {
158+
shell.userShellrcPath = rcfilePath(".zshrc")
159+
}
156160
case "ksh":
157161
shell.name = shKsh
158162
shell.userShellrcPath = rcfilePath(".kshrc")
@@ -365,6 +369,7 @@ func (s *DevboxShell) linkShellStartupFiles(shellSettingsDir string) {
365369
filenames = append(filenames, ".zimrc")
366370

367371
for _, filename := range filenames {
372+
// The userShellrcPath should be set to ZDOTDIR already.
368373
fileOld := filepath.Join(filepath.Dir(s.userShellrcPath), filename)
369374
_, err := os.Stat(fileOld)
370375
if errors.Is(err, fs.ErrNotExist) {
@@ -376,12 +381,11 @@ func (s *DevboxShell) linkShellStartupFiles(shellSettingsDir string) {
376381
}
377382

378383
fileNew := filepath.Join(shellSettingsDir, filename)
379-
380-
if err := os.Link(fileOld, fileNew); err == nil {
381-
debug.Log("Linked shell startup file %s to %s", fileOld, fileNew)
382-
} else {
384+
cmd := exec.Command("cp", fileOld, fileNew)
385+
if err := cmd.Run(); err != nil {
383386
// This is a best-effort operation. If there's an error then log it for visibility but continue.
384-
debug.Log("Error linking zsh setting file from %s to %s: %v", fileOld, fileNew, err)
387+
debug.Log("Error copying zsh setting file from %s to %s: %v", fileOld, fileNew, err)
388+
continue
385389
}
386390
}
387391
}

0 commit comments

Comments
 (0)