Created
May 1, 2020 21:31
-
-
Save joehillen/670db7e45898a51b414cde036ab79837 to your computer and use it in GitHub Desktop.
Trying out Deno
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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