From a6dc100241a78872ddacad39ff35be005e36a7da Mon Sep 17 00:00:00 2001 From: Pulak Kanti Bhowmick Date: Sun, 3 Nov 2024 21:23:26 +0600 Subject: [PATCH 1/5] add atmos in PS1 Signed-off-by: Pulak Kanti Bhowmick --- internal/exec/shell_utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/exec/shell_utils.go b/internal/exec/shell_utils.go index 9ddb12db7..d7e4e7fcf 100644 --- a/internal/exec/shell_utils.go +++ b/internal/exec/shell_utils.go @@ -154,6 +154,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, "PS1=atmos>") 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)) @@ -187,7 +188,6 @@ func execTerraformShellCommand( } shellCommand = bashPath } - shellCommand = shellCommand + " -l" } u.LogDebug(cliConfig, fmt.Sprintf("Starting process: %s\n", shellCommand)) From affe28427bdaf10b0a0f3b73b64f81a6052f82ca Mon Sep 17 00:00:00 2001 From: Pulak Kanti Bhowmick Date: Tue, 5 Nov 2024 12:04:00 +0600 Subject: [PATCH 2/5] add review suggestions Signed-off-by: Pulak Kanti Bhowmick --- internal/exec/shell_utils.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/exec/shell_utils.go b/internal/exec/shell_utils.go index d7e4e7fcf..a6fd60fde 100644 --- a/internal/exec/shell_utils.go +++ b/internal/exec/shell_utils.go @@ -154,7 +154,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, "PS1=atmos>") + 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)) @@ -184,9 +184,15 @@ 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 } } From d335ef286fe478cd60a1ad3e5dbb4454f328ed6a Mon Sep 17 00:00:00 2001 From: Pulak Kanti Bhowmick Date: Wed, 6 Nov 2024 00:25:24 +0600 Subject: [PATCH 3/5] Update internal/exec/shell_utils.go Co-authored-by: Erik Osterman (CEO @ Cloud Posse) --- internal/exec/shell_utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/exec/shell_utils.go b/internal/exec/shell_utils.go index a6fd60fde..bcf112d43 100644 --- a/internal/exec/shell_utils.go +++ b/internal/exec/shell_utils.go @@ -154,7 +154,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)) + 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)) From 8e98f65722ff07ef8725da889ceb7180efd75708 Mon Sep 17 00:00:00 2001 From: Pulak Kanti Bhowmick Date: Sun, 10 Nov 2024 23:03:56 +0600 Subject: [PATCH 4/5] fix for zsh Signed-off-by: Pulak Kanti Bhowmick --- internal/exec/shell_utils.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/exec/shell_utils.go b/internal/exec/shell_utils.go index bcf112d43..38742b3a5 100644 --- a/internal/exec/shell_utils.go +++ b/internal/exec/shell_utils.go @@ -194,6 +194,10 @@ func execTerraformShellCommand( shellCommand = bashPath } } + + if shellCommand == "/bin/zsh" { + shellCommand = shellCommand + " -d -f -i" + } } u.LogDebug(cliConfig, fmt.Sprintf("Starting process: %s\n", shellCommand)) From 8525b86a2a5ecb4900e04a6bd2914864a63e6c30 Mon Sep 17 00:00:00 2001 From: Pulak Kanti Bhowmick Date: Mon, 11 Nov 2024 02:56:28 +0600 Subject: [PATCH 5/5] compare only shell name Signed-off-by: Pulak Kanti Bhowmick --- internal/exec/shell_utils.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/exec/shell_utils.go b/internal/exec/shell_utils.go index 38742b3a5..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" @@ -195,7 +196,8 @@ func execTerraformShellCommand( } } - if shellCommand == "/bin/zsh" { + shellName := filepath.Base(shellCommand) + if shellName == "zsh" { shellCommand = shellCommand + " -d -f -i" } }