dotfiles/.local/bin/scripts/predate

16 lines
555 B
Plaintext
Raw Normal View History

2021-11-25 12:20:13 +00:00
#!/bin/sh -e
# Add the modification date in front of the filename
2021-11-25 12:20:13 +00:00
IFS='\n'
2022-01-11 12:23:56 +00:00
test "$1" = -s && short=true && shift
2023-08-07 15:45:59 +00:00
test ! -f "$1" && rename=true && name=$1 && shift || rename=false
for file
2021-11-25 12:20:13 +00:00
do mv --verbose --interactive "$file" \
2022-03-15 15:56:22 +00:00
"$(latest "$file" | head -2 | tail -1 |
2023-08-07 15:45:59 +00:00
cut -c$(test "$short" && echo "3,4,6,7,9,10" || echo "-10"))$(
if $rename
then echo "$(test "$name" && echo "_$name").${file##*.}"
else echo "_$file" | sed 's/^_2\?\([0-9]\{2,3\}\)-\([0-9]\{2\}\)\(-[0-9]\{2\}\)\?_\?/_/'
fi)"
done
2021-11-25 12:20:13 +00:00
# stat --format %y "$file" | cut -d' ' -f1