Open History to see the last commit
1// @effect-diagnostics nodeBuiltinImport:off
2import * as NodeOS from "node:os";
3import * as NodePath from "node:path";
4
5/**
6 * Expand a leading `~` (or `~/…`, `~\…`) in a user-supplied path to the
7 * current user's home directory. Spawned processes don't get shell
8 * expansion, so env vars like `CODEX_HOME=~/.codex-work` would be passed
9 * verbatim and treated as relative paths by the receiver.
10 *
11 * Matches the behavior of the other `expandHomePath` helpers in the
12 * workspace layers and CLI bootstrap: `~` alone and both `~/` and `~\`
13 * separators are handled. Returns the input unchanged if it doesn't
14 * start with `~` or is empty. Does not handle `~user` (other-user)
15 * expansion.
16 */
17export function expandHomePath(value: string): string {
18 if (!value) return value;
19 if (value === "~") return NodeOS.homedir();
20 if (value.startsWith("~/") || value.startsWith("~\\")) {
21 return NodePath.join(NodeOS.homedir(), value.slice(2));
22 }
23 return value;
24}