-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
82 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ words: | |
- dearmor | ||
- CPPFLAGS | ||
- cpprc | ||
- untildified | ||
- Cpython | ||
- DCMAKE | ||
- deps | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,39 @@ | ||
import { join } from "path" | ||
import untildify from "untildify" | ||
import { isSudo } from "admina" | ||
import { homedir } from "os" | ||
|
||
export function untildifyUser(path: string) { | ||
if (isSudo() && typeof process.env.SUDO_USER === "string") { | ||
export function userHomeDir() { | ||
if (isSudo() && typeof process.env.SUDO_USER === "string" && process.env.SUDO_USER !== "") { | ||
// use the user profile even if root | ||
if (process.platform === "darwin") { | ||
return join("/Users/", process.env.SUDO_USER, path) | ||
return join("/Users/", process.env.SUDO_USER) | ||
} else { | ||
return join("/home/", process.env.SUDO_USER, path) | ||
return join("/home/", process.env.SUDO_USER) | ||
} | ||
} else { | ||
return untildify(`~/${path}`) | ||
const maybeHomeDir = homedir() | ||
if (maybeHomeDir === "") { | ||
return undefined | ||
} | ||
return maybeHomeDir | ||
} | ||
} | ||
|
||
const tildeRegex = /^~(?=$|\/|\\)/ | ||
|
||
/** | ||
* Replaces a tilde with the user's home directory | ||
* | ||
* @example UntildifyUser("~/foo") // /home/user/foo | ||
* | ||
* @param path The path to untildify | ||
* @returns The untildified path | ||
*/ | ||
export function untildifyUser(path: string) { | ||
const maybeHomeDir = userHomeDir() | ||
if (maybeHomeDir === undefined) { | ||
return path | ||
} | ||
|
||
return path.replace(tildeRegex, maybeHomeDir) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters