setup-cpp/src/utils/path/untildify.ts

17 lines
476 B
TypeScript
Raw Normal View History

import { join } from "path"
import untildify from "untildify"
2022-08-08 08:24:44 +08:00
import { isRoot } from "sudo-tools"
export function untildify_user(path: string) {
if (isRoot() && typeof process.env.SUDO_USER === "string") {
// use the user profile even if root
if (process.platform === "darwin") {
return join("/Users/", process.env.SUDO_USER, path)
} else {
return join("/home/", process.env.SUDO_USER, path)
}
} else {
return untildify(`~/${path}`)
}
}