Skip to content

Commit

Permalink
feat: indicator for nested profile
Browse files Browse the repository at this point in the history
  • Loading branch information
sunggun-yu committed Feb 21, 2024
1 parent 763b510 commit 25caa08
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
13 changes: 13 additions & 0 deletions internal/shell/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
})
})
})

0 comments on commit 25caa08

Please sign in to comment.