Skip to main content

collapse_home

Function collapse_home 

Source
pub fn collapse_home(path: &str) -> String
Expand description

Replace a leading $HOME in path with ~. Returns path unchanged if it doesn’t start under home, or if home isn’t known.

On Windows, std::fs::canonicalize returns paths with the verbatim (\\?\) or UNC-verbatim (\\?\UNC\) prefix; both are stripped here before any other processing so the status row never shows the raw extended-length form (e.g. \\?\D:\wwwroot\xingyu-api).

On Windows the comparison is case-insensitive because canonicalize may normalise the path to a different casing than dirs::home_dir() returns (e.g. C:\Users\… vs c:\users\…).

Used by the status row + welcome page to keep long paths readable.