ycategories-presentation/categories/renameSlideFic.sh

37 lines
842 B
Bash
Raw Normal View History

2012-11-07 13:50:33 +00:00
#!/usr/bin/env zsh
2012-11-09 16:05:27 +00:00
# get script directory
if [[ ${0[0]} = '/' ]]; then
scriptdir="${0:h}"
else
scriptdir="$PWD/${0:h}"
fi
cd $scriptdir
for rep in ??_*(/); do
print "renaming html of $rep"
cd $rep
i=10
for fic in *.html; do
2012-11-26 08:48:19 +00:00
title=$( <$fic grep h2 | sed 's/<[^>]*>//g;s/&[^;]*;//g;s/[^a-zA-Z0-9]/_/g;s/__*/_/g;s/^_//;s/_$//;')
2012-11-09 16:05:27 +00:00
if ((i<100)); then
num="0$i"
else
num="$i"
fi
((i+=10))
newfic=${num}_$title.${fic:e}
[[ $fic == $newfic ]] && { continue }
[[ -e $newfic ]] && {
print -- "$newfic already exists!" >&2
continue
}
mv $fic $newfic
mdfic=${fic:r}.md
newmdfic=${newfic:r}.md
[[ -e $mdfic ]] && mv $mdfic $newmdfic
2012-11-09 16:05:27 +00:00
done
cd $scriptdir
2012-11-07 13:50:33 +00:00
done