-
Notifications
You must be signed in to change notification settings - Fork 0
/
picd
executable file
·63 lines (52 loc) · 1.17 KB
/
picd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
# files up to 5am are considered part of the previous day
TIME_OFFSET_HOURS=5
TIME_OFFSET_SECONDS=$((TIME_OFFSET_HOURS * 3600))
format="%Y-%m-%d.%a"
dryRun=0
while [[ $1 == -* ]]; do
if [ "$1" = "-m" ]; then
format="%Y-%m.week-%U"
shift
continue
fi
if [ "$1" = "-f" ]; then
format="$2";
shift
shift
continue
fi
if [ "$1" = "-h" ]; then
cat <<EOF
picd [-m] [-f timeFormat] [-h] file [file..]
-m save in weekly+monthly folders (%Y-%m.week-$U)
-f fmt use time format fmt
-h print this help
-n dry run - don't actually do anything
EOF
exit 0
fi
if [ "$1" = "-n" ]; then
dryRun=1
shift
continue
fi
echo "${0}: Unrecognized flag: $1"
exit 1
done
if [[ "x$format" = "x" || "x$format" = "x." || "x$format" = "x.." ]]; then
echo "Empty or illegal format '""$format""'. Stopping."
exit 1
fi
for file; do
stats=($(stat -r "$file"))
#echo "$file - stats# is ${#stats}, stats is $stats"
modTime=${stats[9]}
#echo "$file - $modTime = $(date -r $modTime)"
dirName=$(date -r $((modTime - TIME_OFFSET_SECONDS)) +"${format}")
echo mv "$file" $dirName
if [[ $dryRun = 0 ]]; then
mkdir -p $dirName
mv -i "$file" $dirName
fi
done