|
1 | 1 | #!/usr/bin/env -S pkgx --quiet deno^2.1 run --ext=ts --allow-sys=uid --allow-run --allow-env=PKGX_DIR,HOMEBREW_PREFIX,HOME,PATH --allow-read --allow-write |
2 | | -import { SemVer, semver } from "https://deno.land/x/libpkgx@v0.20.3/mod.ts"; |
| 2 | +import { Path, SemVer, semver } from "https://deno.land/x/libpkgx@v0.20.3/mod.ts"; |
3 | 3 | import { dirname, fromFileUrl, join } from "jsr:@std/path@^1"; |
4 | | -import { ensureDir, existsSync } from "jsr:@std/fs@^1"; |
| 4 | +import { ensureDir, existsSync, walk } from "jsr:@std/fs@^1"; |
5 | 5 | import { parseArgs } from "jsr:@std/cli@^1"; |
6 | 6 |
|
7 | 7 | function standardPath() { |
@@ -58,24 +58,24 @@ if (parsedArgs.help) { |
58 | 58 | case "li": |
59 | 59 | await install(args, `${Deno.env.get("HOME")!}/.local`); |
60 | 60 | break; |
| 61 | + case "stub": |
61 | 62 | case "shim": |
62 | 63 | // this uses the old behavior of pkgx v1, which is to install to ~/.local/bin |
63 | 64 | // if we want to write to /usr/local, we need to use sudo |
64 | 65 | await shim(args, `${Deno.env.get("HOME")!}/.local`); |
65 | | - // await shim(args, "/usr/local"); |
66 | 66 | break; |
67 | | - // case "local-shim": |
68 | | - // await shim(args, `${Deno.env.get("HOME")!}/.local`); |
69 | | - // break; |
70 | 67 | case "uninstall": |
71 | 68 | case "rm": |
72 | 69 | case "list": |
73 | 70 | case "ls": |
| 71 | + for await (const path of ls()) { |
| 72 | + console.log(path); |
| 73 | + } |
| 74 | + break; |
74 | 75 | case "up": |
75 | 76 | case "update": |
76 | 77 | case "pin": |
77 | 78 | case "outdated": |
78 | | - case "stub": |
79 | 79 | console.error("%cunimplemented. soz. U EARLY.", "color: red"); |
80 | 80 | Deno.exit(1); |
81 | 81 | break; |
@@ -422,3 +422,20 @@ function get_pkgx() { |
422 | 422 | } |
423 | 423 | throw new Error("no `pkgx` found in `$PATH`"); |
424 | 424 | } |
| 425 | + |
| 426 | +async function* ls() { |
| 427 | + for (const path of [Path.root.join("/usr/local/pkgs"), Path.home().join(".local/pkgs")]) { |
| 428 | + const dirs = [path]; |
| 429 | + let dir: Path | undefined; |
| 430 | + while (dir = dirs.pop()) { |
| 431 | + for await (const [path, { name, isDirectory, isSymlink }] of dir.ls()) { |
| 432 | + if (!isDirectory || isSymlink) continue; |
| 433 | + if (/^v\d+\./.test(name)) { |
| 434 | + yield path; |
| 435 | + } else { |
| 436 | + dirs.push(path); |
| 437 | + } |
| 438 | + } |
| 439 | + } |
| 440 | + } |
| 441 | +} |
0 commit comments