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

Avoid consider PATH updated when the export is commented in the shellrc #12043

Merged

Conversation

JonCholas
Copy link
Contributor

Summary

The way the tool update-shell checks if the command to export the PATH exists or not in the RC files is a blind search, and therefore if finds the command inside comments.

example with .zshenv

This content

# uv
# export PATH="/Users/cholas/.local/bin:$PATH"

Generates the following msg

error: The executable directory /Users/cholas/.local/bin is not in PATH, but the Zsh configuration files are already up-to-date

With this change, that content won't be considered as configured and the following will be added

# uv
export PATH="/Users/cholas/.local/bin:$PATH"

This will make the update-shell more reliable

Test Plan

I tested with and without the change with commented export in zsh in mac. Tested running cargo run -- tool update-shell

@@ -73,7 +73,7 @@ pub(crate) async fn update_shell(printer: Printer) -> Result<ExitStatus> {
// Search for the command in the file, to avoid redundant updates.
match fs_err::tokio::read_to_string(&file).await {
Ok(contents) => {
if contents.contains(&command) {
if contents.lines().any(|line| line.trim() == command.trim()) {
Copy link
Member

Choose a reason for hiding this comment

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

Could we instead skip lines that start with #?

@charliermarsh charliermarsh enabled auto-merge (squash) March 8, 2025 14:23
@charliermarsh charliermarsh added the bug Something isn't working label Mar 8, 2025
@charliermarsh charliermarsh force-pushed the joncholas/improve-update-shell branch from b53977e to d8e4acf Compare March 8, 2025 14:37
@charliermarsh charliermarsh merged commit b239c3e into astral-sh:main Mar 8, 2025
75 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants