7IYRNLJRA7ECAPBKQQK4R4CFE7QWLYVSTOUECVOWNYKGB76VPUUQC
#!/bin/bash
# Based on https://github.com/akkartik/mu1/blob/master/relayout
set -e
if [[ $# -eq 0 && `git diff HEAD |wc -l` -gt 0 ]]
then
echo "Uncommitted changes"
exit
fi
# Phase 1
#? index=0
#? ls [0-9]* |sort -n |
#? while read file
#? do
#? while [[ $file != `printf "%04d" $index`* ]]
#? do
#? echo
#? index=$(($index+1))
#? done
#? echo $file |sed 's/^....-//'
#? index=$(($index+1))
#? done > .layout
root() {
echo $1 |sed 's/^[0-9]*-//'
}
# Phase 2
index=0
cat $1 |
while read file
do
echo $index $file
if [ ! -z $file ]
then
file=$(ls |grep ".-$file\$")
newfile=$(printf "%04d-%s" $index `root $file`)
echo "=> $newfile"
if [[ $newfile != $file ]]
then
echo git mv $file $newfile
git mv $file $newfile
fi
fi
index=$(($index+1))
done