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

Add zsh support #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

ghanta1996
Copy link

@ghanta1996 ghanta1996 commented Jun 9, 2024

Hi

Thanks for the repo. It was helpful to be able to run ROS GUI from docker.

I want to add a small change to your shell script with zsh support.

Thanks


This change is Reviewable

Summary by CodeRabbit

  • New Features

    • Added a ros_dev() function to the user's shell configuration (~/.bashrc or ~/.zshrc) for setting environment variables and running docker-compose for ROS development.
  • Improvements

    • Enhanced the setup.sh script to automatically detect the user's shell and add the ros_dev() function accordingly.
    • Improved script readability and maintainability with refactoring and added comments.
    • Added error handling and user messages for unsupported shells and incorrect function usage.

Copy link

coderabbitai bot commented Jun 9, 2024

Walkthrough

The setup.sh script has been enhanced to dynamically add a ros_dev() function to the user's shell configuration file (~/.bashrc or ~/.zshrc) based on the detected shell. This function sets necessary environment variables and runs docker-compose for ROS development, ensuring that it only gets added once and includes proper error handling and messaging.

Changes

Files Change Summary
setup.sh Added logic to dynamically add ros_dev() function to user's shell configuration file based on detected shell. Includes error handling, proper formatting, and ensures function is added only once.

Poem

In the land of scripts, a change so bright,
ros_dev() now takes flight,
In bash or zsh, it finds its way,
To set your vars and save the day.
Docker-compose, with ease you'll run,
For ROS dev, it's second to none.
A rabbit's touch, the job well done! 🐇✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range and nitpick comments (2)
setup.sh (2)

14-14: Ensure consistent argument checking logic.

The argument checking logic uses modulo operation to ensure an even number of arguments, which might not be clear at first glance. Consider adding a comment to explain this logic for future maintainability.

Also applies to: 36-36


24-24: Consider using absolute paths for docker-compose.

Using relative paths like cd "$SCRIPT_DIR" can sometimes lead to errors if the script is called from different directories. It's safer to use absolute paths when invoking commands like docker-compose.

Also applies to: 45-45

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e314e28 and 674fae1.

Files selected for processing (1)
  • setup.sh (1 hunks)
Additional context used
Shellcheck
setup.sh

[error] 1-1: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. (SC2148)


[warning] 5-5: SCRIPT_DIR appears unused. Verify use (or export if used externally). (SC2034)


[error] 31-31: Use 'elif' instead of 'else if' (or put 'if' on new line if nesting). (SC1075)

Additional comments not posted (2)
setup.sh (2)

Line range hint 5-5: Verify the usage of SCRIPT_DIR or consider exporting it if used externally.

Shellcheck has indicated that SCRIPT_DIR appears unused within the script. Please verify if it's being used in a way not visible in this snippet or consider exporting it if it's intended for external use.

Tools
Shellcheck

[error] 31-31: Use 'elif' instead of 'else if' (or put 'if' on new line if nesting). (SC1075)


57-57: Confirm the completion message is appropriate.

The script ends with a "Done" message. Verify that this message accurately reflects the completion of all intended actions, especially in error scenarios.

setup.sh Outdated Show resolved Hide resolved
setup.sh Outdated Show resolved Hide resolved
@adeeb10abbas
Copy link
Owner

adeeb10abbas commented Jun 9, 2024

Thanks a ton! @ghanta1996

I would not copy paste the same code twice. Here's how I would do it

# Define the ros_dev function
ros_dev_function='ros_dev() {
    # Check if the correct number of arguments were provided
    if (( $# % 2 != 0 )); then
        echo "Usage: ros_dev <container_name1> <project_path1> [<container_name2> <project_path2> ...]"
        return 1
    fi
    while (( $# >= 2 )); do
        # Set environment variables
        export ROS_DEV_CONTAINER_NAME=$1
        export ROS_PROJECT_PATH=$2
        shift 2
        # Run docker-compose from the correct directory
        cd "$SCRIPT_DIR" && docker-compose up -d --build
    done
}'

# Determine the shell and appropriate rc file
if [[ $SHELL == "/bin/bash" ]]; then
    rc_file="$HOME/.bashrc"
elif [[ $SHELL == "/bin/zsh" ]]; then
    rc_file="$HOME/.zshrc"
else
    echo "Unsupported shell"
    exit 1
fi

# Check if the function already exists and add it if not
if ! grep -q "ros_dev()" "$rc_file"; then
    echo "$ros_dev_function" >> "$rc_file"
    echo "ros_dev function added to $rc_file file"
else
    echo "ros_dev function already exists in $rc_file file"
fi

echo "Done"

If you want to add those changes that would be great!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 674fae1 and 59bbd91.

Files selected for processing (1)
  • setup.sh (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • setup.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants