Skip to content

Instantly share code, notes, and snippets.

@WingTillDie
Last active July 14, 2023 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WingTillDie/2499d4003ab0285c86b69acc2c49affd to your computer and use it in GitHub Desktop.
Save WingTillDie/2499d4003ab0285c86b69acc2c49affd to your computer and use it in GitHub Desktop.
Fix WSL ERROR UtilConnectToInteropServer in tmux
#!/usr/bin/env bash
# Fix WSL interop problem when attached to tmux
# fix ERROR: UtilConnectToInteropServer:300: connect failed 2:
#
# Modified from
# https://superuser.com/questions/1602401/vscode-terminal-behaves-strangely-when-opening-a-project-that-is-inside-wsl2
# Fix by search lowest ancestor of tmux: client that is init
# Then sets wsl interop id as pid of that init
fix_wsl_interop_tmux() {
ancestors_of_tmux_client() {
pstree --show-pids | fgrep 'tmux: client'; }
get_pid_of_lowest_ancestor_init() {
select_numbers() {
grep -oP '\d+'; }
select_line_-3(){
tail -n3 | head -n1; }
select_numbers | select_line_-3
}
REAL_WSL_INTEROP_ID=$(ancestors_of_tmux_client | get_pid_of_lowest_ancestor_init)
sudo ln -s /run/WSL/${REAL_WSL_INTEROP_ID}_interop $WSL_INTEROP
}
fix_wsl_interop_tmux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment