@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 37 lines 1.47 KB
Raw
1 import * as HostProcess from "@t3tools/shared/HostProcess";
2 import * as Effect from "effect/Effect";
3 import * as FileSystem from "effect/FileSystem";
4 import * as Path from "effect/Path";
5
6 // `wslpath` honours the distro's configurable automount root, so the fake maps drives under a temp dir.
7 export const makeFakeWslHost = Effect.gen(function* () {
8 const fileSystem = yield* FileSystem.FileSystem;
9 const path = yield* Path.Path;
10 const mountRoot = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3code-wsl-mnt-" });
11 const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3code-wsl-bin-" });
12 const wslpath = path.join(binDir, "wslpath");
13 yield* fileSystem
14 .writeFileString(
15 wslpath,
16 [
17 "#!/bin/sh",
18 '[ "$1" = "-u" ] || exit 1',
19 "p=$(printf '%s' \"$2\" | tr '\\\\' '/')",
20 "drive=$(printf '%s' \"$p\" | cut -c1 | tr 'A-Z' 'a-z')",
21 `printf '%s/%s%s\\n' '${mountRoot}' "$drive" "\${p#?:}"`,
22 "",
23 ].join("\n"),
24 )
25 .pipe(Effect.orDie);
26 yield* fileSystem.chmod(wslpath, 0o755).pipe(Effect.orDie);
27 const environment = {
28 ...HostProcess.Environment.defaultValue(),
29 PATH: `${binDir}:${HostProcess.Environment.defaultValue().PATH ?? ""}`,
30 };
31 const underWsl = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
32 effect.pipe(
33 Effect.provideService(HostProcess.Platform, "linux"),
34 Effect.provideService(HostProcess.Environment, environment),
35 );
36 return { mountRoot, underWsl };
37 });