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

Commit

Permalink
Add the Windows host IP to the hosts file (e.g. xdebug.remote_host=<h…
Browse files Browse the repository at this point in the history
…ostname>.wsl)
  • Loading branch information
Nicolas GIROD committed Oct 6, 2020
1 parent 8f8b76d commit 444a395
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cmd/wsl2host/pkg/service/service.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package service

import (
"os"
"fmt"
"regexp"
"strings"
Expand All @@ -11,6 +12,8 @@ import (
"github.com/shayne/go-wsl2-host/pkg/hostsapi"

"github.com/shayne/go-wsl2-host/pkg/wslapi"

"github.com/shayne/go-wsl2-host/pkg/wslcli"
)

const tld = ".wsl"
Expand Down Expand Up @@ -132,6 +135,22 @@ func Run(elog debug.Log) error {
}
}

hostIP, err := wslcli.GetHostIP()

if err == nil {
hostname, err := os.Hostname()
hostAlias := distroNameToHostname(hostname)
err = hapi.AddEntry(&hostsapi.HostEntry{
IP: hostIP,
Hostname: hostAlias,
Comment: wsl2hosts.DistroComment(hostname),
})

if err == nil {
updated = true
}
}

if updated {
err = hapi.Write()
if err != nil {
Expand Down

0 comments on commit 444a395

Please sign in to comment.