-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #225 from aminya/pipx [skip ci]
fix: install to the user home when using pipx as sudo
- Loading branch information
Showing
18 changed files
with
180 additions
and
79 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
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
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) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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