Skip to content

Instantly share code, notes, and snippets.

@DanWahlin
Created June 27, 2023 20:30
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 DanWahlin/fa34e4be63cb206a5ebfaeb6cc794e8b to your computer and use it in GitHub Desktop.
Save DanWahlin/fa34e4be63cb206a5ebfaeb6cc794e8b to your computer and use it in GitHub Desktop.
Uses rsync to sync folders on a machine.
syncFolders() {
printf "%s" "Target Folder: "
read localFolder
printf "%s" "Destination Folder: "
read remoteFolder
printf "%s" "Excluded Folders (separated by space): "
read excludedFolders
array=($(echo "$excludedFolders" | tr ' ' '\n'))
# if [ -z "${excludedFolders[@]}" ]; then
# excludedFolders=(".git" "node_modules")
# fi
echo "Running sync to move from $localFolder to $remoteFolder"
exclude_flags=()
for i in "${array[@]}"
do
echo "Excluding $i"
exclude_flags+=("--exclude=$i" "--exclude=*/$i")
done
echo "${exclude_flags[@]}"
rsync -av "${exclude_flags[@]}" "$localFolder" "$remoteFolder"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment