Skip to content

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

Merged
Andriy Knysh (aknysh) merged 9 commits into
mainfrom
pulak/DEV-1819
Nov 11, 2024
Merged

Andriy Knysh (aknysh) merged 9 commits into
mainfrom
pulak/DEV-1819

Conversation

@pkbhowmick

@pkbhowmick Pulak Kanti Bhowmick (pkbhowmick) commented Nov 3, 2024 •

Copy link
Copy Markdown
Contributor

what

why

image

references

  • New Features

    • Customized command prompt for the interactive shell with the addition of the "atmos>" prefix.
  • Bug Fixes

    • Enhanced shell behavior by removing the unnecessary -l flag for non-Windows systems and implementing a fallback to sh if bash is unavailable.
    • Improved handling for the /bin/zsh shell with additional flags.

Closes #495

Signed-off-by: Pulak Kanti Bhowmick <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 3, 2024 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes involve modifications to the execTerraformShellCommand function in internal/exec/shell_utils.go. A new environment variable PS1 is added to customize the shell prompt to include the stack and component names, improving user awareness in the subshell. The removal of the -l flag for non-Windows systems alters shell behavior regarding environment initialization. The function's core functionality and logging remain unchanged.

Changes

File Change Summary
internal/exec/shell_utils.go Added PS1 environment variable to customize the shell prompt; removed -l flag for non-Windows systems; updated shell command fallback logic.

Assessment against linked issues

Objective Addressed Explanation
Make it more obvious in the terminal when launching the subshell (DEV-1899) ✅
A way to prefix component names using an inheritable metadata (DEV-1819) ❌ This change does not address the prefixing feature.

Possibly related PRs

  • get atmos config and vendor from .yaml or .yml #736: This PR modifies the handling of configuration files, specifically allowing for the retrieval of configuration from both .yaml and .yml files, which relates to the overall environment setup and configuration management in the main PR's context.

Suggested reviewers

  • osterman
  • aknysh

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
internal/exec/shell_utils.go (2)

157-157: Consider enhancing the PS1 prompt with more context.

The PS1 change is a solid improvement, warrior! However, we can make it even more informative by including the stack and component names. This would further prevent confusion when working with multiple stacks.

-	componentEnvList = append(componentEnvList, "PS1=atmos>")
+	componentEnvList = append(componentEnvList, fmt.Sprintf("PS1=[atmos:%s/%s]> ", stack, component))

Line range hint 192-201: Add error handling for shell command resolution.

The shell command resolution is robust, but we should handle the case where neither SHELL env var is set nor bash is found.

 		if len(shellCommand) == 0 {
 			bashPath, err := exec.LookPath("bash")
 			if err != nil {
+				// 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", err)
+				}
+				shellCommand = shPath
+			} else {
 				return err
+			}
 			}
 			shellCommand = bashPath
 		}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4098092 and a6dc100.

📒 Files selected for processing (1)
  • internal/exec/shell_utils.go (1 hunks)
🔇 Additional comments (1)
internal/exec/shell_utils.go (1)

Line range hint 159-165: LGTM! Clear and informative debug logging.

The debug logging provides excellent context about the shell environment. This helps users understand exactly where they are and what variables are set.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Nov 3, 2024
Comment thread internal/exec/shell_utils.go Resolved
Comment thread internal/exec/shell_utils.go Resolved
@osterman

Copy link
Copy Markdown
Member

Also see the CodeRabbit (@coderabbitai) suggestions to enhance the prompt and improve error handling if shell is not set

#761 (review)

@coderabbitai

coderabbitai Bot commented Nov 3, 2024

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

Erik Osterman (Cloud Posse) (@osterman): To enhance the prompt, we can adjust the PS1 variable to include more context, such as the current stack or component name, making it clearer when in atmos terraform shell mode. For example:

componentEnvList = append(componentEnvList, fmt.Sprintf("PS1=atmos-%s> ", stackName))

Additionally, improving error handling by checking if the shellCommand is not set will prevent potential issues. We can add a check like:

if shellCommand == "" {
    return fmt.Errorf("no shell found to launch the interactive session")
}

These changes will enhance the user experience by providing clearer context and preventing errors when the shell is not configured properly.

Signed-off-by: Pulak Kanti Bhowmick <[email protected]>
coderabbitai[bot]
coderabbitai Bot previously approved these changes Nov 5, 2024
@osterman

Copy link
Copy Markdown
Member

When I tried this with SHELL=/bin/zsh, I get the following error:

image

@osterman

Copy link
Copy Markdown
Member

It's working for me with SHELL=/bin/bash

image

(note: the MacOS default is now /bin/zsh)

@osterman

Copy link
Copy Markdown
Member

For zsh, we'll probably need to do zsh --no-rcs for PS1 to be assigned

Co-authored-by: Erik Osterman (CEO @ Cloud Posse) <[email protected]>
@pkbhowmick

Pulak Kanti Bhowmick (pkbhowmick) commented Nov 5, 2024 •

Copy link
Copy Markdown
Contributor Author

For zsh, we'll probably need to do zsh --no-rcs for PS1 to be assigned

with -i that few argument issue is fixed for zsh but with this suggestion custom PS1 still not working for zsh

@osterman

Copy link
Copy Markdown
Member

with -i that few argument issue is fixed for zsh but with this suggestion custom PS1 still not working for zsh

What's the full command that you tried?

@osterman Erik Osterman (Cloud Posse) (osterman) added the minor New features that do not break anything label Nov 6, 2024
@pkbhowmick

Copy link
Copy Markdown
Contributor Author

with -i that few argument issue is fixed for zsh but with this suggestion custom PS1 still not working for zsh

What's the full command that you tried?

I just added -i https://github.com/cloudposse/atmos/pull/761/files#diff-e3cce11c219f517c242174f1f00e72c2173ad0cefda9ec3e0775cb46ada22f63L195 here

@osterman

Copy link
Copy Markdown
Member

Pulak Kanti Bhowmick (@pkbhowmick) what are the next steps here?

@osterman

Copy link
Copy Markdown
Member

Pulak Kanti Bhowmick (@pkbhowmick) this works for me:

PS1="Foobar> " zsh -d -f -i
Foobar> 
Foobar>

Signed-off-by: Pulak Kanti Bhowmick <[email protected]>
@pkbhowmick

Copy link
Copy Markdown
Contributor Author

Pulak Kanti Bhowmick (@pkbhowmick) this works for me:

PS1="Foobar> " zsh -d -f -i
Foobar> 
Foobar>

Hi Erik Osterman (Cloud Posse) (@osterman), thanks a lot. It is working now
image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aknysh Andriy Knysh (aknysh) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aknysh
Andriy Knysh (aknysh) merged commit d502eb0 into main Nov 11, 2024
@aknysh
Andriy Knysh (aknysh) deleted the pulak/DEV-1819 branch November 11, 2024 17:29
@github-actions

Copy link
Copy Markdown

These changes were released in v1.104.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor New features that do not break anything

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

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

3 participants