Created
June 27, 2023 20:30
-
-
Save DanWahlin/fa34e4be63cb206a5ebfaeb6cc794e8b to your computer and use it in GitHub Desktop.
Uses rsync to sync folders on a machine.
This file contains 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
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