nef-to-jpg.sh
· 785 B · Bash
原始檔案
#!/bin/bash
# Converts all files in current directory
# ending with *.NEF to JPEGs (.jpg) using darktable-cli
# Based on:
# https://askubuntu.com/a/1337782
set -eo pipefail
err() {
( 1>&2 echo -e "[Error]\n$1\nExiting" )
exit 1
}
main() {
command -v "darktable-cli" &>/dev/null || err "Expected command darktable-cli to be available"
local nefs=()
mapfile -t nefs < <(find_nefs)
local i=
local nef=
local jpgname=
for (( i = 0; i < ${#nefs[@]}; i++ )); do
nef="${nefs[i]}"
jpgname="$( basename -s ".NEF" "$nef" ).jpg"
echo "$i: ${nef} -> ${jpgname}"
[ -f "$jpgname" ] && err "JPEG file named \"${jpgname}\" already exists"
darktable-cli "$nef" "$jpgname"
done
echo "Done"
}
find_nefs() {
find . -type f -iname '*.nef'
}
main "$@"
| 1 | #!/bin/bash |
| 2 | |
| 3 | # Converts all files in current directory |
| 4 | # ending with *.NEF to JPEGs (.jpg) using darktable-cli |
| 5 | # Based on: |
| 6 | # https://askubuntu.com/a/1337782 |
| 7 | |
| 8 | set -eo pipefail |
| 9 | |
| 10 | err() { |
| 11 | ( 1>&2 echo -e "[Error]\n$1\nExiting" ) |
| 12 | exit 1 |
| 13 | } |
| 14 | |
| 15 | main() { |
| 16 | command -v "darktable-cli" &>/dev/null || err "Expected command darktable-cli to be available" |
| 17 | |
| 18 | local nefs=() |
| 19 | mapfile -t nefs < <(find_nefs) |
| 20 | |
| 21 | local i= |
| 22 | local nef= |
| 23 | local jpgname= |
| 24 | for (( i = 0; i < ${#nefs[@]}; i++ )); do |
| 25 | nef="${nefs[i]}" |
| 26 | jpgname="$( basename -s ".NEF" "$nef" ).jpg" |
| 27 | |
| 28 | echo "$i: ${nef} -> ${jpgname}" |
| 29 | |
| 30 | [ -f "$jpgname" ] && err "JPEG file named \"${jpgname}\" already exists" |
| 31 | |
| 32 | darktable-cli "$nef" "$jpgname" |
| 33 | done |
| 34 | |
| 35 | echo "Done" |
| 36 | } |
| 37 | |
| 38 | find_nefs() { |
| 39 | find . -type f -iname '*.nef' |
| 40 | } |
| 41 | |
| 42 | main "$@" |