Skip to content

Commit 7998294

Browse files
committed
fixes detecting homebrew pkgx
1 parent e59e8f9 commit 7998294

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

pkgm.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
#!/usr/bin/env -S pkgx deno^2.1 run --ext=ts --allow-sys=uid --allow-run=pkgx,/usr/bin/sudo --allow-env=PKGX_DIR,HOME --allow-read=/usr/local/pkgs
1+
#!/usr/bin/env -S pkgx deno^2.1 run --ext=ts --allow-sys=uid --allow-run=pkgx,/usr/bin/sudo --allow-env=PKGX_DIR,HOMEBREW_PREFIX,HOME --allow-read=/usr/local/pkgs
22
import { dirname, fromFileUrl, join } from "jsr:@std/path@^1";
33
import { ensureDir, existsSync } from "jsr:@std/fs@^1";
44
import { parse as parse_args } from "jsr:@std/flags@0.224.0";
55
import * as semver from "jsr:@std/semver@^1";
66

7+
const standardPath = (() => {
8+
const basePath = "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin";
9+
const homebrew = `${Deno.env.get("HOMEBREW_PREFIX") || "/opt/homebrew"}/bin`;
10+
if (existsSync(homebrew)) {
11+
return `${homebrew}:${basePath}`;
12+
} else {
13+
return basePath;
14+
}
15+
})();
16+
717
const parsedArgs = parse_args(Deno.args, {
818
alias: {
919
v: "version",
@@ -18,7 +28,7 @@ if (parsedArgs.help) {
1828
args: ["gh", "repo", "view", "pkgxdev/pkgm"],
1929
clearEnv: true,
2030
env: {
21-
"PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
31+
"PATH": standardPath,
2232
"HOME": Deno.env.get("HOME")!,
2333
},
2434
}).spawn().status;
@@ -69,7 +79,7 @@ async function install(args: string[]) {
6979
args = args.map((x) => `+${x}`);
7080

7181
const env: Record<string, string> = {
72-
"PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
82+
"PATH": standardPath,
7383
};
7484
const set = (key: string) => {
7585
const x = Deno.env.get(key);

0 commit comments

Comments
 (0)