Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change PS1 to show that atmos is in the atmos terraform shell mode #761

Merged
merged 9 commits into from
Nov 11, 2024
18 changes: 15 additions & 3 deletions internal/exec/shell_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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"
osterman marked this conversation as resolved.
Show resolved Hide resolved

shellName := filepath.Base(shellCommand)
if shellName == "zsh" {
shellCommand = shellCommand + " -d -f -i"
}
}

u.LogDebug(cliConfig, fmt.Sprintf("Starting process: %s\n", shellCommand))
Expand Down