Repository: nushell/nushell
File: crates/nu-command/src/path/relative_to.rs (Rust)

Code before:
                    from_type: "string".into(),
                    span,
                    help: None,
                },
                span,
            )
        }
    }
}

/// Check if the current filesystem is typically case-insensitive
fn is_case_insensitive_filesystem() -> bool {
    // Windows and macOS typically have case-insensitive filesystems
    cfg!(any(target_os = "windows", target_os = "macos"))
}

/// Try to strip prefix in a case-insensitive manner
fn try_case_insensitive_strip_prefix(lhs: &Path, rhs: &Path) -> Option<std::path::PathBuf> {
    let lhs_components: Vec<_> = lhs.components().collect();
    let rhs_components: Vec<_> = rhs.components().collect();

    if rhs_components.len() > lhs_components.len() {
        return None;
    }

    for (lhs_comp, rhs_comp) in lhs_components.iter().zip(rhs_components.iter()) {
        match (lhs_comp, rhs_comp) {
            (std::path::Component::Normal(lhs_name), std::path::Component::Normal(rhs_name)) => {
                if lhs_name.to_string_lossy().to_lowercase()
                    != rhs_name.to_string_lossy().to_lowercase()
                {
                    return None;
                }
            }
            // Non-Normal components must match exactly
            _ if lhs_comp != rhs_comp => {
                return None;
            }
            _ => {}
        }
    }

    let mut result = std::path::PathBuf::new();
    for component in lhs_components.iter().skip(rhs_components.len()) {
        result.push(component);
    }

    Some(result)
}

#[cfg(test)]

Review comment (suggestion):
I'm thinking that we don't need to collect `components` at first time.  We can just use the `Components` iterator.
```
let mut lhs_components = lhs.components();
let mut rhs_components = rhs.components();

let mut common_cnt = 0;
for (lhs_comp, rhs_comp) in lhs.components().zip(rhs.components()) {
    ...
    common_cnt += 1
}
let mut result = std::path::PathBuf::new();
for component in lhs_components.iter().skip(common_cnt) {
    result.push(component);
}
```

Code after:
                    from_type: "string".into(),
                    span,
                    help: None,
                },
                span,
            )
        }
    }
}

/// Check if the current filesystem is typically case-insensitive
fn is_case_insensitive_filesystem() -> bool {
    // Windows and macOS typically have case-insensitive filesystems
    cfg!(any(target_os = "windows", target_os = "macos"))
}

/// Try to strip prefix in a case-insensitive manner
fn try_case_insensitive_strip_prefix(lhs: &Path, rhs: &Path) -> Option<std::path::PathBuf> {
    let mut lhs_components = lhs.components();
    let mut rhs_components = rhs.components();

    // Compare components case-insensitively
    loop {
        match (lhs_components.next(), rhs_components.next()) {
            (Some(lhs_comp), Some(rhs_comp)) => {
                match (lhs_comp, rhs_comp) {
                    (
                        std::path::Component::Normal(lhs_name),
                        std::path::Component::Normal(rhs_name),
                    ) => {
                        if lhs_name.to_string_lossy().to_lowercase()
                            != rhs_name.to_string_lossy().to_lowercase()
                        {
                            return None;
                        }
                    }
                    // Non-Normal components must match exactly
                    _ if lhs_comp != rhs_comp => {
                        return None;
                    }
                    _ => {}
                }
            }
            (Some(lhs_comp), None) => {
                // rhs is fully consumed, but lhs has more components
                // This means rhs is a prefix of lhs, collect remaining lhs components
                let mut result = std::path::PathBuf::new();
                // Add the current lhs component that wasn't matched
                result.push(lhs_comp);
                // Add all remaining lhs components
                for component in lhs_components {