env: only set DISPLAY on WSL if an Xserver is reachable
Neovim always uses `xclip` as the clipboard provider if DISPLAY is set. Therefore, if we set it unconditionally, `xclip` hangs while trying to reach the server if this hasn't been started, causing all sorts of chaos.
This commit is contained in:
parent
f174612d03
commit
210978ab8f
1 changed files with 10 additions and 4 deletions
12
home/.zshenv
12
home/.zshenv
|
@ -48,12 +48,18 @@ export ZDOTDIR="$XDG_CONFIG_HOME/zsh"
|
||||||
#
|
#
|
||||||
[ "$(uname -s)" = "Darwin" ] || source "$XDG_CONFIG_HOME/shell/path.sh"
|
[ "$(uname -s)" = "Darwin" ] || source "$XDG_CONFIG_HOME/shell/path.sh"
|
||||||
|
|
||||||
# Set $DISPLAY if running in WSL
|
# Set $DISPLAY if running in WSL and an Xserver is reachable
|
||||||
#
|
#
|
||||||
# How to configure Windows Firewall for Xserver: https://skeptric.com/wsl2-xserver/
|
# How to configure Windows Firewall for Xserver: https://skeptric.com/wsl2-xserver/
|
||||||
# How to check if running in WSL: https://stackoverflow.com/a/61014411
|
# How to check if running in WSL: https://stackoverflow.com/a/61014411
|
||||||
if [ $(uname -r | sed -n 's/.*\( *Microsoft *\).*/\1/ip') ]; then
|
if [ -n "$(uname -r | sed -n 's/.*\( *Microsoft *\).*/\1/ip')" ]; then
|
||||||
export DISPLAY=$(awk '/nameserver/ {print $2; exit}' /etc/resolv.conf 2>/dev/null):0.0
|
xdisplay="$(awk '/nameserver/ {print $2; exit}' /etc/resolv.conf 2>/dev/null):0.0"
|
||||||
|
if command -v xset >/dev/null 2>&1; then
|
||||||
|
if DISPLAY="$xdisplay" timeout '0.2s' xset q >/dev/null 2>&1; then
|
||||||
|
export DISPLAY="$xdisplay"
|
||||||
export LIBGL_ALWAYS_INDIRECT=1
|
export LIBGL_ALWAYS_INDIRECT=1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
unset xdisplay
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue