Skip to content

Commit a9ee3cd

Browse files
authored
Write shellrc file on fish (unified env) (#661)
## Summary Before this change, we would panic (in unified env) when using `fish`, because we didn't have the user's init file to write into devbox shellrc. Now we write the shellrc regardless of whether the user's init file is available or not. ## How was it tested? ``` SHELL=fish DEVBOX_FEATURE_UNIFIED_ENV=1 devbox shell ``` (Also tested that non-unified-env doesn't break.
1 parent 7fb3374 commit a9ee3cd

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

internal/nix/shell.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,6 @@ func (s *Shell) execCommandInShell() (string, string, string) {
356356
}
357357

358358
func (s *Shell) writeDevboxShellrc() (path string, err error) {
359-
if s.userShellrcPath == "" {
360-
// If this happens, then there's a bug with how we detect shells
361-
// and their shellrc paths. If the shell is unknown or we can't
362-
// determine the shellrc path, then we should launch a fallback
363-
// shell instead.
364-
panic("writeDevboxShellrc called with an empty user shellrc path; use the fallback shell instead")
365-
}
366359

367360
// We need a temp dir (as opposed to a temp file) because zsh uses
368361
// ZDOTDIR to point to a new directory containing the .zshrc.
@@ -371,11 +364,11 @@ func (s *Shell) writeDevboxShellrc() (path string, err error) {
371364
return "", fmt.Errorf("create temp dir for shell init file: %v", err)
372365
}
373366

374-
// This is a best-effort to include the user's existing shellrc. If we
375-
// can't read it, then just omit it from the devbox shellrc.
376-
userShellrc, err := os.ReadFile(s.userShellrcPath)
377-
if err != nil {
378-
userShellrc = []byte{}
367+
// This is a best-effort to include the user's existing shellrc.
368+
userShellrc := []byte{}
369+
if s.userShellrcPath != "" {
370+
// If we can't read it, then just omit it from the devbox shellrc.
371+
userShellrc, _ = os.ReadFile(s.userShellrcPath)
379372
}
380373

381374
// If the user already has a shellrc file, then give the devbox shellrc

0 commit comments

Comments
 (0)