Initial commit

Signed-off-by: Ilan Bigio <ilan@openai.com>
This commit is contained in:
Ilan Bigio
2025-04-16 12:56:08 -04:00
commit 59a180ddec
163 changed files with 30587 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
import path from "path";
export function shortenPath(p: string, maxLength = 40): string {
const home = process.env["HOME"];
// Replace home directory with '~' if applicable.
const displayPath =
home !== undefined && p.startsWith(home) ? p.replace(home, "~") : p;
if (displayPath.length <= maxLength) {
return displayPath;
}
const parts = displayPath.split(path.sep);
let result = "";
for (let i = parts.length - 1; i >= 0; i--) {
const candidate = path.join("~", "...", ...parts.slice(i));
if (candidate.length <= maxLength) {
result = candidate;
} else {
break;
}
}
return result || displayPath.slice(-maxLength);
}
export function shortCwd(maxLength = 40): string {
return shortenPath(process.cwd(), maxLength);
}