Open History to see the last commit
1import * as OS from "node:os";
2import { Effect, Path } from "effect";
3import { readPathFromLoginShell } from "@t3tools/shared/shell";
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 = readPathFromLoginShell(shell);
11 if (result) {
12 process.env.PATH = result;
13 }
14 } catch {
15 // Silently ignore — keep default PATH
16 }
17}
18
19export const expandHomePath = Effect.fn(function* (input: string) {
20 const { join } = yield* Path.Path;
21 if (input === "~") {
22 return OS.homedir();
23 }
24 if (input.startsWith("~/") || input.startsWith("~\\")) {
25 return join(OS.homedir(), input.slice(2));
26 }
27 return input;
28});
29
30export const resolveStateDir = Effect.fn(function* (raw: string | undefined) {
31 const { join, resolve } = yield* Path.Path;
32 if (!raw || raw.trim().length === 0) {
33 return join(OS.homedir(), ".t3", "userdata");
34 }
35 return resolve(yield* expandHomePath(raw.trim()));
36});