]> git.scottworley.com Git - picsort/blob - pic-mv
A manually-callable cleanup utility
[picsort] / pic-mv
1 #!/bin/bash
2
3 destdir=
4 if [[ -e .default-pic-mv-destdir ]];then
5 destdir=$( < .default-pic-mv-destdir )
6 fi
7
8 exposure=
9 rotate=
10 while getopts d:e:r: opt;do
11 case $opt in
12 d) destdir=$OPTARG;;
13 e) exposure=$OPTARG;;
14 r) rotate=$OPTARG;;
15 esac
16 done
17 shift `expr $OPTIND - 1`
18
19 if [[ -z "$destdir" ]];then
20 echo "Please specify a destdir with -d or .default-pic-mv-destdir" >&2
21 exit 1
22 fi
23
24 file="$1"
25 name="$2"
26
27 # Find next number
28 max=$(ls "$destdir" | sed -rn "s/^$name ([0-9]+).jpeg$/\1/p" | sort -n | tail -n1)
29 if [[ "$max" ]];then
30 number=$((max + 1))
31 else
32 number=1
33 fi
34
35 out="$destdir/$name $number.jpeg"
36
37 if [[ "$file" == *.NEF ]];then
38 base="${file%.NEF}"
39 NEFout="$destdir/$name $number.NEF"
40 if [[ "$rotate" ]];then
41 numeric_exposure=$(dc <<< "2k $exposure 4 / 3.5-p")
42 pics-run-ufraw "$numeric_exposure" "$file" "$out" "$rotate"
43 else
44 mv -vi "$exposure/$base.jpeg" "$out"
45 fi
46 touch -r "$file" "$out"
47 mv -vi "$file" "$NEFout"
48 chmod 644 "$NEFout"
49 else
50 if [[ "$rotate" ]];then
51 sed -i "s/^# ROBOTS_INSERT_THINGS_HERE\$/\"$name $number.jpeg\" => $rotate,\n&/" "$destdir/rotations.php"
52 fi
53 mv -vi "$file" "$out"
54 fi
55 chmod 644 "$out"