-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyshrc.wsl
41 lines (37 loc) · 1.37 KB
/
myshrc.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
#!/hint/bash
#
# Extra WSL-specific functionality. To use the full functionality here, a few things need to be
# installed and configured on both the WSL Host and Guest sides.
#
# Host (Windows):
# * Install VcXsrv and save a vcxsrv.xlaunch file somewhere (default C:\Users\$USER\vcxsrv.xlaunch)
#
# Guest (Linux):
# * Install wsl2-get-display somewhere in PATH
# * Install wslview somewhere in PATH (wslu package)
# * Set environment variables in ~/myshrc_local if needed
# - WSL_WINDOWS_USER Windows username ($USER)
# - WSL_VCXSRV_PASTH Windows path to vcxsrv.xlaunch (C:\Users\$WSL_WINDOWS_USER\vcxsrv.xlaunch)
# * Source ~/linuxfiles/myshrc.wsl in ~/myshrc_local
if [[ -z "$TMUX" ]] && which wsl2-get-display &>/dev/null; then
export DISPLAY="$(wsl2-get-display)"
fi
xlaunch() {
local windows_user="${WSL_WINDOWS_USER:-${USER}}"
local vcxsrv_path="${WSL_VCXSRV_PATH:-C:\\Users\\${windows_user}\\vcxsrv.xlaunch}"
if ! which wsl2-get-display &>/dev/null; then
echo "Error: wsl2-get-display not found"
return 1
fi
local _d="$(wsl2-get-display -t50)"
if [[ -n "$_d" ]]; then
export DISPLAY="$_d"
else
wslview "$vcxsrv_path"
sleep 0.5
export DISPLAY="$(wsl2-get-display -t50 -r100)"
fi
if [[ -n "$TMUX" ]]; then
tmux set-environment DISPLAY "$DISPLAY"
fi
}