Skip to content

Commit 150a256

Browse files
authored
[devbox] Default to the shell already being used (#2478)
## Summary `devbox shell` now uses the `$SHELL` environment variable to start the same shell that the user is already using. Exported additional environment variables that make it possible to configure a prompt when inside a devbox shell. ## How was it tested? Compiled and ran on example project. ## Is this change backwards-compatible? Yes
1 parent 88887fe commit 150a256

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

boxcli/shell.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ func runShellCmd(cmd *cobra.Command, args []string) error {
2424
return errors.WithStack(err)
2525
}
2626

27+
// TODO: If we're inside a devbox shell already, don't re-run.
2728
return box.Shell()
2829
}

nix/nix.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import (
1111

1212
func Shell(path string) error {
1313
cmd := exec.Command("nix-shell")
14+
// Default to the shell already being used.
15+
shell := os.Getenv("SHELL")
16+
if shell != "" {
17+
cmd.Args = append(cmd.Args, "--command", shell)
18+
}
1419
cmd.Stdin = os.Stdin
1520
cmd.Stdout = os.Stdout
1621
cmd.Stderr = os.Stderr

tmpl/shell.nix.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ let
55
}) {};
66
in with pkgs;
77
mkShell {
8+
shellHook = "export name=devbox IN_NIX_SHELL=0; DEVBOX_SHELL_ENABLED=1;";
89
packages = [
910
{{- range .Packages}}
1011
{{.}}

0 commit comments

Comments
 (0)