Skip to content

Instantly share code, notes, and snippets.

@agross
Last active October 12, 2019 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agross/1b0478956b04d279aa27282dc9591f7e to your computer and use it in GitHub Desktop.
Save agross/1b0478956b04d279aa27282dc9591f7e to your computer and use it in GitHub Desktop.
Back up images, skip those having a DNG or RAW file in a "raw" subdirectory
#!/usr/bin/env zsh
set -eu
setopt pipe_fail
setopt extended_glob
mkdir -p images \
images/only-raw/raw \
images/only-jpeg \
images/jpeg-and-raw/raw \
touch images/only-raw/raw/include.raw \
images/only-jpeg/include.jpeg \
images/jpeg-and-raw/include.jpg \
images/jpeg-and-raw/exclude-raw.jpg \
images/jpeg-and-raw/exclude-dng.jpg \
images/jpeg-and-raw/exclude-dng.jpg \
images/jpeg-and-raw/include-noraw.jpg \
images/jpeg-and-raw/raw/exclude-raw.raw \
images/jpeg-and-raw/raw/exclude-dng.dng \
images/jpeg-and-raw/raw/include-noraw.something
exclude_images_with_raws() {
local dir=${REPLY%/*}
# Files in "/raw" directories are always included.
if [[ $dir == */raw ]]; then
return
fi
local basename_without_ext=${${REPLY%.*}##*/}
local raw=$dir/raw/$basename_without_ext.(dng|raw)
# ~ = treat variable contents as a glob
# #q = http://zsh.sourceforge.net/Doc/Release/Conditional-Expressions.html#Conditional-Expressions
# . = normal files
# N = empty if nothing matches (makes the test fail)
if [[ -n $~raw(#q.N) ]]; then
>&2 printf 'Excluding %s because there is a raw at %s\n' $REPLY $raw
reply=()
fi
}
() {
printf 'File list:\n'
cat $1
printf 'rsync:\n'
rsync -av --files-from=$1 . backup
} =(print -l images/**/*(.+exclude_images_with_raws))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment