Skip to content

Instantly share code, notes, and snippets.

@kevinushey
Created August 28, 2024 22:08
Show Gist options
  • Save kevinushey/2351194ba540627831fa2d58073c097a to your computer and use it in GitHub Desktop.
Save kevinushey/2351194ba540627831fa2d58073c097a to your computer and use it in GitHub Desktop.
A wrapper for 'cp', which avoids copying un-needed directories.
#!/usr/bin/env sh
# use a plain old cp if R_CMD is not set
if [ -z "${R_CMD}" ]; then
/bin/cp "$@"
exit
fi
# TODO: default version of rsync on macOS is buggy;
# modification times are not preserved even when requested
# trim off flags intended for cp
while [ "$#" -ne "0" ]; do
case "$1" in
--help)
/bin/cp --help
exit
;;
--version)
/bin/cp --version
exit
;;
--)
shift
break
;;
-*)
shift
;;
*)
break
;;
esac
done
# figure out flags to pass to rsync
if [ -n "${VERBOSE}" ] && [ "${VERBOSE}" != "0" ]; then
FLAGS="-avr"
else
FLAGS="-aqr"
fi
# write out an exclude file
SOURCE="$1"
EXCLUDEFILE=$(mktemp)
cat > "${EXCLUDEFILE}" <<- EOF
${SOURCE}/.Rproj.user
${SOURCE}/.git
${SOURCE}/revdep
${SOURCE}/packrat
${SOURCE}/renv/library
${SOURCE}/renv/cellar
${SOURCE}/tags
EOF
# perform the copy
rsync "${FLAGS}" --exclude-from="${EXCLUDEFILE}" "$@"
STATUS="$?"
# clean up exclude file
rm "${EXCLUDEFILE}"
exit "${STATUS}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment