From d502eb04e122760b9384ff6b6a111635f7d1abf7 Mon Sep 17 00:00:00 2001 From: Pulak Kanti Bhowmick Date: Mon, 11 Nov 2024 23:29:31 +0600 Subject: [PATCH] change PS1 to show that atmos is in the `atmos terraform shell` mode (#761) * add atmos in PS1 Signed-off-by: Pulak Kanti Bhowmick * add review suggestions Signed-off-by: Pulak Kanti Bhowmick * Update internal/exec/shell_utils.go Co-authored-by: Erik Osterman (CEO @ Cloud Posse) * fix for zsh Signed-off-by: Pulak Kanti Bhowmick * compare only shell name Signed-off-by: Pulak Kanti Bhowmick --------- Signed-off-by: Pulak Kanti Bhowmick Co-authored-by: Erik Osterman (CEO @ Cloud Posse) Co-authored-by: Andriy Knysh --- internal/exec/shell_utils.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/internal/exec/shell_utils.go b/internal/exec/shell_utils.go index 9ddb12db7..c142c75cd 100644 --- a/internal/exec/shell_utils.go +++ b/internal/exec/shell_utils.go @@ -7,6 +7,7 @@ import ( "io" "os" "os/exec" + "path/filepath" "runtime" "strings" @@ -154,6 +155,7 @@ func execTerraformShellCommand( componentEnvList = append(componentEnvList, fmt.Sprintf("TF_CLI_ARGS_import=-var-file=%s", varFile)) componentEnvList = append(componentEnvList, fmt.Sprintf("TF_CLI_ARGS_destroy=-var-file=%s", varFile)) componentEnvList = append(componentEnvList, fmt.Sprintf("TF_CLI_ARGS_console=-var-file=%s", varFile)) + componentEnvList = append(componentEnvList, fmt.Sprintf("PS1=atmos:%s/%s> ", stack, component)) u.LogDebug(cliConfig, "\nStarting a new interactive shell where you can execute all native Terraform commands (type 'exit' to go back)") u.LogDebug(cliConfig, fmt.Sprintf("Component: %s\n", component)) @@ -183,11 +185,21 @@ func execTerraformShellCommand( if len(shellCommand) == 0 { bashPath, err := exec.LookPath("bash") if err != nil { - return err + // Try fallback to sh if bash is not available + shPath, shErr := exec.LookPath("sh") + if shErr != nil { + return fmt.Errorf("no suitable shell found: %v", shErr) + } + shellCommand = shPath + } else { + shellCommand = bashPath } - shellCommand = bashPath } - shellCommand = shellCommand + " -l" + + shellName := filepath.Base(shellCommand) + if shellName == "zsh" { + shellCommand = shellCommand + " -d -f -i" + } } u.LogDebug(cliConfig, fmt.Sprintf("Starting process: %s\n", shellCommand))