-
-
Save kevinushey/2351194ba540627831fa2d58073c097a to your computer and use it in GitHub Desktop.
A wrapper for 'cp', which avoids copying un-needed directories.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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