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

Make it more obvious in the terminal when launching the subshell via atmos terraform shell #495

Closed
nitrocode opened this issue Dec 19, 2023 · 9 comments · Fixed by #761
Closed
Labels
enhancement New feature or request UpWork

Comments

@nitrocode
Copy link
Member

Describe the Feature

Sometimes we're in the subshell and forget that the subshell is specific to a stack and then try to plan/apply a different stack which leads to errors.

If the PS1 or something can be modified to show that atmos is in the atmos terraform shell mode, it would be very helpful.

Expected Behavior

For example, if you're in the shell stack ue1-eks, then atmos should throw a warning if you're trying to run atmos within the shell against another stack.

Use Case

Forgetting that you're in a subshell

Describe Ideal Solution

Maybe a warning or a PS1 change to show you're in a subshell

Alternatives Considered

No response

Additional Context

No response

@osterman
Copy link
Member

Yes, I could see that the PS1 maybe should be overridden to something plain like (atmos) ue1-eks > so it's clear you're in the shell and for which particular stack. We could then maybe disable this behavior by passing --override-ps1=false

@rajhawaldar
Copy link

May I work on this issue @osterman ?

@osterman
Copy link
Member

Possibly, could you suggest your approach?

@rajhawaldar
Copy link

I thought of introducing the PS1 environment variable in the componentEnvList at internal/exec/shell_utils.go#L163. I tried this on the forked setup locally but the PS1 value is not getting override :( . So for now, I don't have any alternate approach.

@osterman osterman added the enhancement New feature or request label Feb 3, 2024
@osterman
Copy link
Member

Good news, bad news. @rajhawaldar @nitrocode

Bad News

Bad news is, I think little can be done here, since we're just invoking a "login" (-l) shell based on SHELL. The login shell will always overwrite the environment. There's no general solution that will work, other than the developer modifying their own .zshrc or .bashrc file with a custom prompt.

Alternatively, we could make shell a parameter in the atmos.yaml, and if set, use that over the SHELL env. In that case, the default shell can be changed to not include -l, which then will not load the RC files.

Good News

The line @rajhawaldar shows that it already passes the component's deep merged environment. The prompt is controlled by PS1 (for bash).

Just set the following in the Stack configuration and it should work.

env:
  ATMOS_PS1: "atmos>"
  # This works, but gets overridden by the shell's rc file.
  # PS1: "atmos>"

Then in your local rc file, check for that variable and set the prompt to it. It's not the ideal solution, and there's nothing about calling an interactive.

If @rajhawaldar wants to add the shell parameter to the atmos.yaml, and it solves the PS1, that would be appreciated.

@kevcube
Copy link
Contributor

kevcube commented Mar 21, 2024

@osterman @rajhawaldar maybe something slightly higher-level, like finding some common way to edit PS1 through shell tools that many humans use, like starship.rs or oh-my-zsh etc.

@rajhawaldar
Copy link

rajhawaldar commented May 30, 2024

@osterman Apologies for the late response. Do we really need to introduce the new shell parameter to the atmos.yaml file. The code already checks for the SHELL environment variable at line /internal/exec/shell_utils.go#L173. If user sets their desired SHELL in .zshrc or .bashrc file, then our code already picks it.

I performed following steps on my local setup, and it does the job.

  1. I setup /usr/bin/sh as my default shell in .bashrc file
    export SHELL="/usr/bin/sh"

  2. I removed the following line from the code to not run any shell as login shell.

    shellCommand = shellCommand + " -l"

  3. Added componentEnvList = append(componentEnvList, "PS1=atmos>") environment variable here

    Env: append(os.Environ(), componentEnvList...),

Then I just got the desired prompt as below,

image

@osterman, let me know your thoughts on this approach.

Copy link
Member

I think we can do that. I think we should implement that, and add PS1 unless it explicitly set in the atmos config.

@osterman osterman added the UpWork label Oct 11, 2024 — with Linear
@osterman
Copy link
Member

osterman commented Nov 8, 2024

This is addressed in #761

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request UpWork
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants