Skip to content

Commit 7db4122

Browse files
committed
pkgm ls
1 parent d95af34 commit 7db4122

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

pkgm.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/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";
33
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";
55
import { parseArgs } from "jsr:@std/cli@^1";
66

77
function standardPath() {
@@ -58,24 +58,24 @@ if (parsedArgs.help) {
5858
case "li":
5959
await install(args, `${Deno.env.get("HOME")!}/.local`);
6060
break;
61+
case "stub":
6162
case "shim":
6263
// this uses the old behavior of pkgx v1, which is to install to ~/.local/bin
6364
// if we want to write to /usr/local, we need to use sudo
6465
await shim(args, `${Deno.env.get("HOME")!}/.local`);
65-
// await shim(args, "/usr/local");
6666
break;
67-
// case "local-shim":
68-
// await shim(args, `${Deno.env.get("HOME")!}/.local`);
69-
// break;
7067
case "uninstall":
7168
case "rm":
7269
case "list":
7370
case "ls":
71+
for await (const path of ls()) {
72+
console.log(path);
73+
}
74+
break;
7475
case "up":
7576
case "update":
7677
case "pin":
7778
case "outdated":
78-
case "stub":
7979
console.error("%cunimplemented. soz. U EARLY.", "color: red");
8080
Deno.exit(1);
8181
break;
@@ -422,3 +422,20 @@ function get_pkgx() {
422422
}
423423
throw new Error("no `pkgx` found in `$PATH`");
424424
}
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

Comments
 (0)