2022-01-20 03:58:10 +08:00
|
|
|
import { join } from "path"
|
|
|
|
import untildify from "untildify"
|
2022-08-26 18:09:19 +08:00
|
|
|
import { isSudo } from "admina"
|
2022-01-20 03:58:10 +08:00
|
|
|
|
2022-08-08 11:04:59 +08:00
|
|
|
export function untildifyUser(path: string) {
|
2022-08-08 08:29:05 +08:00
|
|
|
if (isSudo() && typeof process.env.SUDO_USER === "string") {
|
2022-01-20 03:58:10 +08:00
|
|
|
// use the user profile even if root
|
2022-04-25 07:24:58 +08:00
|
|
|
if (process.platform === "darwin") {
|
|
|
|
return join("/Users/", process.env.SUDO_USER, path)
|
|
|
|
} else {
|
|
|
|
return join("/home/", process.env.SUDO_USER, path)
|
|
|
|
}
|
2022-01-20 03:58:10 +08:00
|
|
|
} else {
|
|
|
|
return untildify(`~/${path}`)
|
|
|
|
}
|
|
|
|
}
|