Documentation
¶
Overview ¶
Package wslrun runs, from magpie on Windows, a command that is installed only in a WSL distro: Claude Code signed in to inside Ubuntu, say. The command is found in a distro that is running (a stopped one is never started to look), and run there through wsl.exe, in the distro's own home and login, with what magpie hands it (its config directory, the files it writes, its own executable for a helper) told by their paths inside the distro.
Index ¶
- Variables
- func Distros(b []byte) []string
- func Forget()
- type Tool
- func (t Tool) Command(ctx context.Context, args ...string) *exec.Cmd
- func (t Tool) Env(env []string, names ...string) []string
- func (t Tool) Exe() (string, error)
- func (t Tool) Linux(win string) string
- func (t Tool) Probe(ctx context.Context, args ...string) *exec.Cmd
- func (t Tool) Stop(mark string)
Constants ¶
This section is empty.
Variables ¶
var On = runtime.GOOS == "windows"
On is whether there is WSL to look in: on Windows, or in tests.
var Run = func(timeout time.Duration, args ...string) ([]byte, error) { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() cmd := proc.CommandContext(ctx, "wsl.exe", args...) cmd.Env = append(os.Environ(), "WSL_UTF8=1") return cmd.Output() }
Run runs wsl.exe and returns what it printed; a var for tests.
Functions ¶
Types ¶
type Tool ¶
type Tool struct {
Distro string // as wsl.exe -l names it
Path string // the command, inside the distro
PATH string // the distro's PATH it was found on, which it may need (node)
Mount string // where Windows' drives are mounted: "/mnt/"
Host string // the Windows host's address inside the distro, "" when it is 127.0.0.1 (mirrored networking)
}
A Tool is a command of a WSL distro's own.
func Find ¶
Find is the command name of a running WSL distro's own, the default distro first. ok is false off Windows, without WSL, or when no running distro has it.
func Known ¶
Known is the tool Find found last for name, however long ago, without looking again: for a page to say where it runs without waiting on WSL.
func (Tool) Command ¶
Command is the wsl.exe that runs t with args, in the distro, on the PATH it was found on. Nothing of the distro's shell runs: what the run is given of Windows' environment is what Env passes. ctx ending ends the run inside the distro too: killing wsl.exe alone leaves it there (a `claude auth login` would wait on for a browser that never comes).
func (Tool) Env ¶
Env is env for a run of t: WSLENV names the variables of env that go into the distro — those in names, their values Windows paths when they end in /p (WSL then gives the distro's path for them), and the proxy variables, whose proxy on this machine's loopback is the Windows host's address under NAT.
func (Tool) Exe ¶
Exe is magpie's own executable as a run in the distro starts it (a Windows program, which WSL runs on Windows).
func (Tool) Linux ¶
Linux is where Windows path win is inside the distro: C:\Users\me is /mnt/c/Users/me. A path on no drive letter is given back as it is.