IsWSL returns true if the current environment is Windows Subsystem for Linux
()
| 9 | |
| 10 | // IsWSL returns true if the current environment is Windows Subsystem for Linux |
| 11 | func IsWSL() bool { |
| 12 | // Check /proc/version for Microsoft signature |
| 13 | if versionFile, err := os.Open("/proc/version"); err == nil { |
| 14 | defer versionFile.Close() |
| 15 | scanner := bufio.NewScanner(versionFile) |
| 16 | if scanner.Scan() { |
| 17 | version := scanner.Text() |
| 18 | return strings.Contains(strings.ToLower(version), "microsoft") |
| 19 | } |
| 20 | } |
| 21 | return false |
| 22 | } |
| 23 | |
| 24 | // IsOnWindowsPartition returns true if the current working directory is on a Windows partition |
| 25 | // This is detected by checking if the path starts with /mnt/ (typical WSL mount point) |