Skip to content

Commit

Permalink
Avoid consider PATH updated when the export is commented in the shell…
Browse files Browse the repository at this point in the history
…rc (#12043)

## Summary

<!-- What's the purpose of the change? What does it do, and why? -->
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`

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
  • Loading branch information
JonCholas and charliermarsh authored Mar 8, 2025
1 parent 3c220c8 commit b239c3e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/uv/src/commands/tool/update_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ 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()
.map(str::trim)
.filter(|line| !line.starts_with('#'))
.any(|line| line.contains(&command))
{
debug!(
"Skipping already-updated configuration file: {}",
file.simplified_display()
Expand Down

0 comments on commit b239c3e

Please sign in to comment.