Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit 444a395

Browse files
author
Nicolas GIROD
committed
Add the Windows host IP to the hosts file (e.g. xdebug.remote_host=<hostname>.wsl)
1 parent 8f8b76d commit 444a395

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

cmd/wsl2host/pkg/service/service.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package service
22

33
import (
4+
"os"
45
"fmt"
56
"regexp"
67
"strings"
@@ -11,6 +12,8 @@ import (
1112
"github.com/shayne/go-wsl2-host/pkg/hostsapi"
1213

1314
"github.com/shayne/go-wsl2-host/pkg/wslapi"
15+
16+
"github.com/shayne/go-wsl2-host/pkg/wslcli"
1417
)
1518

1619
const tld = ".wsl"
@@ -132,6 +135,22 @@ func Run(elog debug.Log) error {
132135
}
133136
}
134137

138+
hostIP, err := wslcli.GetHostIP()
139+
140+
if err == nil {
141+
hostname, err := os.Hostname()
142+
hostAlias := distroNameToHostname(hostname)
143+
err = hapi.AddEntry(&hostsapi.HostEntry{
144+
IP: hostIP,
145+
Hostname: hostAlias,
146+
Comment: wsl2hosts.DistroComment(hostname),
147+
})
148+
149+
if err == nil {
150+
updated = true
151+
}
152+
}
153+
135154
if updated {
136155
err = hapi.Write()
137156
if err != nil {

0 commit comments

Comments
 (0)