Last active
March 23, 2020 14:37
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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