From 7998294235da01cad01a32f8c03b041f5ae87711 Mon Sep 17 00:00:00 2001 From: Jacob Heider Date: Fri, 17 Jan 2025 16:25:57 -0500 Subject: [PATCH] fixes detecting homebrew `pkgx` --- pkgm.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pkgm.ts b/pkgm.ts index 13dc87b..c51faa0 100755 --- a/pkgm.ts +++ b/pkgm.ts @@ -1,9 +1,19 @@ -#!/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 +#!/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 import { dirname, fromFileUrl, join } from "jsr:@std/path@^1"; import { ensureDir, existsSync } from "jsr:@std/fs@^1"; import { parse as parse_args } from "jsr:@std/flags@0.224.0"; import * as semver from "jsr:@std/semver@^1"; +const standardPath = (() => { + const basePath = "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"; + const homebrew = `${Deno.env.get("HOMEBREW_PREFIX") || "/opt/homebrew"}/bin`; + if (existsSync(homebrew)) { + return `${homebrew}:${basePath}`; + } else { + return basePath; + } +})(); + const parsedArgs = parse_args(Deno.args, { alias: { v: "version", @@ -18,7 +28,7 @@ if (parsedArgs.help) { args: ["gh", "repo", "view", "pkgxdev/pkgm"], clearEnv: true, env: { - "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin", + "PATH": standardPath, "HOME": Deno.env.get("HOME")!, }, }).spawn().status; @@ -69,7 +79,7 @@ async function install(args: string[]) { args = args.map((x) => `+${x}`); const env: Record = { - "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin", + "PATH": standardPath, }; const set = (key: string) => { const x = Deno.env.get(key);