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