Skip to content

Commit

Permalink
Update Windows Subsystem for Linux detection how to
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed May 13, 2021
1 parent 2b546b7 commit cce08bb
Showing 1 changed file with 7 additions and 29 deletions.
36 changes: 7 additions & 29 deletions docs/HOWTO.md
Original file line number Diff line number Diff line change
Expand Up @@ -1039,39 +1039,17 @@ you add or remove brews or casks.

## Use chezmoi on Windows


### Detect Windows Subsystem for Linux (WSL)

WSL can be detected by looking for the string `Microsoft` in
`/proc/kernel/osrelease`, which is available in the template variable
WSL can be detected by looking for the string `Microsoft` or `microsoft` in
`/proc/sys/kernel/osrelease`, which is available in the template variable
`.chezmoi.kernel.osrelease`, for example:

WSL 1:
```
{{ if (eq .chezmoi.os "linux") }}
{{ if (contains "Microsoft" .chezmoi.kernel.osrelease) }}
# WSL-specific code
{{ end }}
{{ end }}
```

WSL 2:
```
{{ if (eq .chezmoi.os "linux") }}
{{ if (contains "microsoft" .chezmoi.kernel.osrelease) }}
# WSL-specific code
{{ end }}
{{ end }}
```

WSL 2 since version 4.19.112:
```
{{ if (eq .chezmoi.os "linux") }}
{{ if (contains "microsoft-WSL2" .chezmoi.kernel.osrelease) }}
# WSL-specific code
{{ end }}
{{ end }}
```
{{ if (eq .chezmoi.os "linux") }}
{{ if (.chezmoi.kernel.osrelease | lower | contains "microsoft") }}
# WSL-specific code
{{ end }}
{{ end }}

### Run a PowerShell script as admin on Windows

Expand Down

1 comment on commit cce08bb

@felipecrs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I always used env variables for that and never found a problem.

https://github.com/felipecrs/dotfiles/blob/master/.chezmoi.toml.tmpl#L12

Please sign in to comment.