setup-cpp/packages/untildify-user/src/index.ts

17 lines
475 B
TypeScript
Raw Normal View History

import { join } from "path"
import untildify from "untildify"
2022-08-08 08:38:34 +08:00
import { isSudo } from "root-tools"
2022-08-08 11:04:59 +08:00
export function untildifyUser(path: string) {
if (isSudo() && 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}`)
}
}