Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

os-jank.ts

39 lines1.0 KB

1import * as OS from "node:os";
2import { Effect, Path } from "effect";
3import { execFileSync } from "node:child_process";
4​
5export function fixPath(): void {
6 if (process.platform !== "darwin") return;
7​
8 try {
9 const shell = process.env.SHELL ?? "/bin/zsh";
10 const result = execFileSync(shell, ["-ilc", "echo -n $PATH"], {
11 encoding: "utf8",
12 timeout: 5000,
13 });
14 if (result) {
15 process.env.PATH = result;
16 }
17 } catch {
18 // Silently ignore — keep default PATH
19 }
21​
22export const expandHomePath = Effect.fn(function* (input: string) {
23 const { join, sep } = yield* Path.Path;
24 if (input === "~") {
25 return OS.homedir();
26 }
27 if (input.startsWith(`~${sep}`)) {
28 return join(OS.homedir(), input.slice(sep.length));
29 }
30 return input;
31});
32​
33export const resolveStateDir = Effect.fn(function* (raw: string | undefined) {
34 const { join, resolve } = yield* Path.Path;
35 if (!raw || raw.trim().length === 0) {
36 return join(OS.homedir(), ".t3", "userdata");
37 }
38 return resolve(yield* expandHomePath(raw.trim()));
39});