From e9c08b48f6c0a3670a3f368449668ac00f72c5e7 Mon Sep 17 00:00:00 2001 From: Lucille Hua Date: Fri, 26 Aug 2022 11:06:03 -0700 Subject: [PATCH] Prevent shell inception from happening (#2643) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Running `devbox shell` inside a devbox shell is strictly prohibited 😆 ## How was it tested? `go build -o devbox cmd/devbox/main.go` `devbox shell` `devbox shell` again ## Is this change backwards-compatible? Yes --- boxcli/shell.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/boxcli/shell.go b/boxcli/shell.go index 41a5e47dbb3..96b02165bff 100644 --- a/boxcli/shell.go +++ b/boxcli/shell.go @@ -5,6 +5,7 @@ package boxcli import ( "fmt" + "os" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -29,7 +30,12 @@ func runShellCmd(cmd *cobra.Command, args []string) error { return errors.WithStack(err) } + inDevboxShell := os.Getenv("DEVBOX_SHELL_ENABLED") + if inDevboxShell != "" && inDevboxShell != "0" && inDevboxShell != "false" { + return errors.New("You are already in an active devbox shell.\nRun 'exit' before calling devbox shell again. Shell inception is not supported.") + } + fmt.Println("Installing nix packages. This may take a while...") - // TODO: If we're inside a devbox shell already, don't re-run. + return box.Shell() }