-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathis-wsl
executable file
·49 lines (41 loc) · 1.65 KB
/
is-wsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
set -euo pipefail
#- is-wsl 1.0
## Usage: is-wsl
## Test if running under Windows Subsystem for Linux.
uname | grep -q -i "linux" || exit 1
# https://stackoverflow.com/a/57836260/465684
[[ -z "${IS_WSL:-}" ]] || {
>&2 echo "$(date +"%H:%M:%S")" "[INFO] Assuming we're running inside WSL because IS_WSL=${IS_WSL}."
exit 0
}
# https://patrickwu.space/wslconf/
[[ ! -e /proc/sys/fs/binfmt_misc/WSLInterop ]] || {
>&2 echo "$(date +"%H:%M:%S")" \
"[INFO] Assuming we're running inside WSL because /proc/sys/fs/binfmt_misc/WSLInterop was found."
exit 0
}
# https://github.com/Microsoft/WSL/issues/423#issuecomment-221627364
if [[ -e /proc/version ]]; then
! cat /proc/version | grep -q -i "Microsoft\|WSL" || {
>&2 cat /proc/version | grep -i "Microsoft\|WSL"
>&2 echo "$(date +"%H:%M:%S")" \
"[INFO] Assuming we're running inside WSL because /proc/version matches Microsoft or WSL."
exit 0
}
fi
# https://github.com/Microsoft/WSL/issues/423#issuecomment-221627364
if [[ -e /proc/sys/kernel/osrelease ]]; then
! cat /proc/sys/kernel/osrelease | grep -q -i "Microsoft\|WSL" || {
>&2 cat /proc/sys/kernel/osrelease | grep -i "Microsoft\|WSL"
>&2 echo "$(date +"%H:%M:%S")" \
"[INFO] Assuming we're running inside WSL because /proc/sys/kernel/osrelease matches Microsoft or WSL."
exit 0
}
fi
! command -v explorer.exe 2>/dev/null >&2 || {
>&2 echo "$(date +"%H:%M:%S")" "[INFO] Assuming we're running inside WSL because explorer.exe command was found."
exit 0
}
>&2 echo "$(date +"%H:%M:%S")" "[INFO] Assuming we're not running inside WSL."
exit 1