-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathos-jank.ts
More file actions
45 lines (40 loc) · 1.34 KB
/
os-jank.ts
File metadata and controls
45 lines (40 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import * as OS from "node:os";
import { Effect, Path } from "effect";
import { readPathFromLoginShell } from "@t3tools/shared/shell";
export function fixPath(): void {
if (process.platform !== "darwin") return;
try {
const shell = process.env.SHELL ?? "/bin/zsh";
const result = readPathFromLoginShell(shell);
if (result) {
process.env.PATH = result;
}
} catch {
// Silently ignore — keep default PATH
}
}
export const expandHomePath = Effect.fn(function* (input: string) {
const { join } = yield* Path.Path;
if (input === "~") {
return OS.homedir();
}
if (input.startsWith("~/") || input.startsWith("~\\")) {
return join(OS.homedir(), input.slice(2));
}
return input;
});
export const resolveStateDir = Effect.fn(function* (raw: string | undefined) {
const { join, resolve } = yield* Path.Path;
if (!raw || raw.trim().length === 0) {
return join(OS.homedir(), ".t3", "userdata");
}
return resolve(yield* expandHomePath(raw.trim()));
});
export const resolveThemesConfigPath = Effect.fn(function* (stateDir: string) {
const path = yield* Path.Path;
const normalizedStateDir = path.resolve(stateDir);
if (path.basename(normalizedStateDir) === "userdata") {
return path.join(path.dirname(normalizedStateDir), "themes.json");
}
return path.join(normalizedStateDir, "themes.json");
});