wslrun

package
v0.1.940 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 14 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var On = runtime.GOOS == "windows"

On is whether there is WSL to look in: on Windows, or in tests.

View Source
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

func Distros

func Distros(b []byte) []string

Distros reads wsl.exe -l -q: UTF-16LE (with or without a BOM), or UTF-8 under WSL_UTF8. Docker Desktop's own distros are left out.

func Forget

func Forget()

Forget drops what Find knows, so the next Find looks again.

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

func Find(name string) (Tool, bool)

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

func Known(name string) (Tool, bool)

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

func (t Tool) Command(ctx context.Context, args ...string) *exec.Cmd

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

func (t Tool) Env(env []string, names ...string) []string

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

func (t Tool) Exe() (string, error)

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

func (t Tool) Linux(win string) string

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.

func (Tool) Probe

func (t Tool) Probe(ctx context.Context, args ...string) *exec.Cmd

Probe is Command for a short answer, as proc.ProbeContext runs one.

func (Tool) Stop

func (t Tool) Stop(mark string)

Stop ends the processes of the run marked mark in the distro.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL