add bins and alternatives
This commit is contained in:
parent
a935bb9893
commit
9f3594e0d3
21 changed files with 210 additions and 10 deletions
33
data/home/.local/bin/prefix.ts
Executable file
33
data/home/.local/bin/prefix.ts
Executable file
|
@ -0,0 +1,33 @@
|
|||
#!/bin/env -S deno run
|
||||
|
||||
import { crayon } from "https://deno.land/x/crayon@3.3.3/mod.ts";
|
||||
|
||||
async function read_line() {
|
||||
const buf = new Uint8Array(1024);
|
||||
const n = await Deno.stdin.read(buf);
|
||||
if (n === null) return null;
|
||||
const line = new TextDecoder().decode(buf.subarray(0, n));
|
||||
return line;
|
||||
}
|
||||
|
||||
function pick<T>(arr: T[]) {
|
||||
const index = Math.floor(arr.length * Math.random());
|
||||
return arr[index];
|
||||
}
|
||||
|
||||
const [prefix] = Deno.args;
|
||||
const colors = [
|
||||
crayon.red,
|
||||
crayon.green,
|
||||
crayon.blue,
|
||||
crayon.yellow,
|
||||
crayon.magenta,
|
||||
];
|
||||
const color = pick(colors);
|
||||
|
||||
while (true) {
|
||||
let line = await read_line();
|
||||
if (line == null) break;
|
||||
line = line.substring(0, line.length - 1);
|
||||
console.log(`${color(`[${prefix}]`)} ${line}`);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue