dotfiles/.local/bin/scripts/predate

12 lines
400 B
Bash
Executable File

#!/bin/sh -e
# Add the modification date in front of the filename
IFS='\n'
test "$1" = -s && short=true && shift
for file
do mv --verbose --interactive "$file" \
"$(latest "$file" | head -2 | tail -1 |
cut -c$(test "$short" && echo "3,4,6,7,9,10" || echo "-10"))_$(
echo "$file" | sed 's/2\?\([0-9]\{2,3\}\)-\([0-9]\{2\}\)\(-[0-9]\{2\}\)\?_\?//')"
done
# stat --format %y "$file" | cut -d' ' -f1