diff --git a/internal/shell/shell.go b/internal/shell/shell.go index 9775b2c..eb6f298 100644 --- a/internal/shell/shell.go +++ b/internal/shell/shell.go @@ -166,6 +166,13 @@ func parseEnvs(envs config.Envs) (errs error) { // appendEnvpProfile set ENVP_PROFILE env var to leverage profile info in the shell prompt, such as starship. func appendEnvpProfile(envs []string, profile string) []string { - envs = append(envs, fmt.Sprintf("%s=%s", envpEnvVarKey, profile)) + // Check if the environment variable already has a value + if value, exists := os.LookupEnv(envpEnvVarKey); exists { + // Append the profile if it is already set + // conjunction with the previous value with ">" to indicate profiles are nested + envs = append(envs, fmt.Sprintf("%s=%s > %s", envpEnvVarKey, value, profile)) + } else { + envs = append(envs, fmt.Sprintf("%s=%s", envpEnvVarKey, profile)) + } return envs } diff --git a/internal/shell/shell_test.go b/internal/shell/shell_test.go index 663a736..bdf78ac 100644 --- a/internal/shell/shell_test.go +++ b/internal/shell/shell_test.go @@ -393,3 +393,16 @@ var _ = Describe("multiple init-script", func() { }) }) }) + +var _ = Describe("nested profiles", func() { + + _ = os.Setenv(envpEnvVarKey, "profile-1") + + When("append another profile into env var", func() { + envs := os.Environ() + envs = appendEnvpProfile(envs, "profile-2") + It("should include previous profile", func() { + Expect(envs).To(ContainElement(fmt.Sprintf("%s=profile-1 > profile-2", envpEnvVarKey))) + }) + }) +})