nixos-config/users/simon/modules/scripts/renumber

15 lines
269 B
Plaintext
Raw Normal View History

#!/usr/bin/env bash
set -euo pipefail
if (( $# < 2 )); then
echo "USAGE: $0 DIGITS FILES"
return 1
fi
digits="$1"
shift 1
i=1
for file in "$@"; do
file="$(readlink -f "$file")"
mv -n "$file" "${file%/*}/$(printf "%0${digits}d" "$i").${file##*.}"
i="$((i+1))"
done