#!/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}`);
}));
