1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/// Returns true if the current process is running under WSL.
#[cfg(target_os = "linux")]
pub fn is_wsl() -> bool {
    if let Ok(b) = std::fs::read("/proc/sys/kernel/osrelease") {
        if let Ok(s) = std::str::from_utf8(&b) {
            let a = s.to_ascii_lowercase();
            return a.contains("microsoft") || a.contains("wsl");
        }
    }
    false
}

/// Returns true if the current process is running under WSL.
#[cfg(not(target_os = "linux"))]
pub fn is_wsl() -> bool {
    false
}