Skip to content

Instantly share code, notes, and snippets.

@joehillen
Created May 1, 2020 21:31
Show Gist options
  • Save joehillen/670db7e45898a51b414cde036ab79837 to your computer and use it in GitHub Desktop.
Save joehillen/670db7e45898a51b414cde036ab79837 to your computer and use it in GitHub Desktop.
Trying out Deno
#!/usr/bin/env -S deno --allow-run
type AbsDir = string;
type AbsFile = string;
type AbsPath = AbsFile | AbsDir;
type RelFile = string;
type RelDir = string;
type Path = RelFile | AbsFile | RelDir | AbsDir;
async function ls(dir: AbsDir): Promise<RelFile[]> {
const p = Deno.run({
cmd: ["ls", "-1", "-a", "--color=never", dir],
stdout: "piped",
});
const { code } = await p.status();
if (code !== 0) {
throw new Error(`ls failed for '${dir}'`);
}
return p.output()
.then((out) =>
new TextDecoder()
.decode(out)
.split("\n")
.filter((f) => f && f !== "." && f !== "..")
);
}
ls("/home/joe").then((files) => files.forEach((f) => console.log({ f })));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment