Skip to content

Instantly share code, notes, and snippets.

@steebchen
Last active March 23, 2020 14:37
Show Gist options
  • Save steebchen/e623c10523cd68c5c3b1710d7106b083 to your computer and use it in GitHub Desktop.
Save steebchen/e623c10523cd68c5c3b1710d7106b083 to your computer and use it in GitHub Desktop.
Shift files in a naming scheme of "xx-yy" where xx is a number to create space at a given index
#!/bin/bash
set -eu
new=$1
for file in $(ls | sort -g -r)
do
filename=$(basename "$file")
number=$(echo $filename | cut -d- -f1)
after=$(printf "%s" "${filename#*-}")
if [ $file = "index.mdx" ]; then
continue
fi
if [ $number -ge $new ]; then
mv "$file" "$(printf "%02d" "$(($number + 1))")-$after"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment