use std::path::{Component, Path, PathBuf};
pub fn resolve_for_display<P>(path: P) -> PathBuf
where
P: AsRef<Path>,
{
let path = path.as_ref();
let absolute = std::path::absolute(path).unwrap_or_else(|_| path.to_path_buf());
let mut out = PathBuf::new();
for component in absolute.components() {
match component {
Component::ParentDir => {
if matches!(out.components().next_back(), Some(Component::Normal(_))) {
out.pop();
} else {
out.push(component);
}
}
Component::CurDir => {}
other => out.push(other),
}
}
out
}