]> git.scottworley.com Git - picsort/blame - pic-mv
mkdir -p sm
[picsort] / pic-mv
CommitLineData
7a7a7a75
SW
1#!/bin/bash
2
d6874f6c
SW
3destdir=
4if [[ -e .default-pic-mv-destdir ]];then
5 destdir=$( < .default-pic-mv-destdir )
6fi
7a7a7a75
SW
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
d6874f6c
SW
19if [[ -z "$destdir" ]];then
20 echo "Please specify a destdir with -d or .default-pic-mv-destdir" >&2
21 exit 1
22fi
23
7a7a7a75
SW
24file="$1"
25name="$2"
26
27# Find next number
28max=$(ls "$destdir" | sed -rn "s/^$name ([0-9]+).jpeg$/\1/p" | sort -n | tail -n1)
29if [[ "$max" ]];then
30 number=$((max + 1))
31else
32 number=1
33fi
34
7e0b085a
SW
35out="$destdir/$name $number.jpeg"
36
7a7a7a75
SW
37if [[ "$file" == *.NEF ]];then
38 base="${file%.NEF}"
9ac8dac0 39 NEFout="$destdir/$name $number.NEF"
7a7a7a75 40 if [[ "$rotate" ]];then
7e0b085a
SW
41 numeric_exposure=$(dc <<< "2k $exposure 4 / 3.5-p")
42 pics-run-ufraw "$numeric_exposure" "$file" "$out" "$rotate"
7a7a7a75 43 else
7e0b085a 44 mv -vi "$exposure/$base.jpeg" "$out"
7a7a7a75 45 fi
5167ae01 46 touch -r "$file" "$out"
9ac8dac0
SW
47 mv -vi "$file" "$NEFout"
48 chmod 644 "$NEFout"
7a7a7a75
SW
49else
50 if [[ "$rotate" ]];then
4ef7056e 51 sed -i "s/^# ROBOTS_INSERT_THINGS_HERE\$/\"$name $number.jpeg\" => $rotate,\n&/" "$destdir/rotations.php"
7a7a7a75 52 fi
7e0b085a 53 mv -vi "$file" "$out"
7a7a7a75 54fi
9ac8dac0 55chmod 644 "$out"