Skip to content

Instantly share code, notes, and snippets.

@drscotthawley
Last active February 13, 2025 21:36
Show Gist options
  • Save drscotthawley/40b83ad37940a141206856c793c3232f to your computer and use it in GitHub Desktop.
Save drscotthawley/40b83ad37940a141206856c793c3232f to your computer and use it in GitHub Desktop.
bash function to rsync Python files in dir & subdirs so I can just use VSCode locally since their Remote eats up server resources
# syncs python files in dir and subdirs so you don't have to run resource-hogging VSCode Remote
# usage: pysync /path/to/local/directory/ user@remote:/path/to/remote/directory/
# UPDATED version: more code than before, but now it follows symbolic links on the remote server instead of just overwriting them
pysync() {
if [ "$#" -ne 2 ]; then
echo "Usage: pysync <source> <destination>"
return 1
fi
fswatch -o "$1" | while read f; do
# Extract the remote host and path
remote_host="${2%%:*}"
remote_path="${2#*:}"
# Get the symlink target
target=$(ssh "$remote_host" "readlink ${remote_path}train-vqgan.py")
if [ ! -z "$target" ]; then
# Temporarily remove the symlink
ssh "$remote_host" "rm ${remote_path}train-vqgan.py"
# Sync directly to the target
rsync -av --include="**/*.py" --include="**/*.ipynb" --exclude="*" \
"$1/train-vqgan.py" "${remote_host}:${target}"
# Recreate the symlink
ssh "$remote_host" "ln -s \"$target\" ${remote_path}train-vqgan.py"
else
# Fall back to normal sync for non-symlinks
rsync -av --include="**/*.py" --include="**/*.ipynb" --exclude="*" "$1" "$2"
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment