add bins and alternatives
This commit is contained in:
parent
a935bb9893
commit
9f3594e0d3
21 changed files with 210 additions and 10 deletions
17
data/home/.local/bin/randomize_filename.ts
Executable file
17
data/home/.local/bin/randomize_filename.ts
Executable file
|
@ -0,0 +1,17 @@
|
|||
#!/bin/env -S deno run -A
|
||||
|
||||
import { basename, dirname } from "https://deno.land/std@0.187.0/path/mod.ts";
|
||||
|
||||
const files = Deno.args;
|
||||
|
||||
function rand_int(ceil = 1000) {
|
||||
return Math.floor(Math.random() * ceil);
|
||||
}
|
||||
|
||||
const keyed = files.map((name) => ({ key: rand_int(files.length), name }));
|
||||
keyed.sort(({ key: a }, { key: b }) => (a - b));
|
||||
await Promise.all(keyed.map(({ name }, index) => {
|
||||
const dir = dirname(name);
|
||||
const base = basename(name);
|
||||
return Deno.rename(`${dir}/${base}`, `${dir}/${index}_${base}`);
|
||||
}));
|
Loading…
Add table
Add a link
Reference in a new issue