Skip to content

Instantly share code, notes, and snippets.

@Stono
Created November 21, 2025 09:37
Show Gist options
  • Select an option

  • Save Stono/5ca1530b0e1b87fa0be0cb1eb91fe5ff to your computer and use it in GitHub Desktop.

Select an option

Save Stono/5ca1530b0e1b87fa0be0cb1eb91fe5ff to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
# Set Chrome user data directory
CHROME_LOCATION="$HOME/Library/Application Support/Google/Chrome"
# Gather profiles into arrays
profile_dirs=()
profile_labels=()
for profile_dir in "$CHROME_LOCATION"/Default "$CHROME_LOCATION"/Profile* "$CHROME_LOCATION"/Guest*; do
[ -d "$profile_dir" ] || continue
pref_file="$profile_dir/Preferences"
if [ -f "$pref_file" ]; then
profile_name=$(grep -o '"name" *: *"[^\"]*"' "$pref_file" | head -1 | sed 's/.*: *"\([^\"]*\)"/\1/')
account_email=$(grep -o '"email" *: *"[^\"]*"' "$pref_file" | head -1 | sed 's/.*: *"\([^\"]*\)"/\1/')
if [ -z "$profile_name" ]; then
profile_name="(no name found)"
fi
if [ -n "$account_email" ]; then
label="$(basename "$profile_dir"): $profile_name ($account_email)"
else
label="$(basename "$profile_dir"): $profile_name"
fi
profile_dirs+=("$profile_dir")
profile_labels+=("$label")
fi
done
# Present options to user
echo "Available Chrome profiles:"
echo ""
for i in "${!profile_labels[@]}"; do
printf "%d) %s\n" "$((i+1))" "${profile_labels[$i]}"
done
echo ""
# Prompt for source profile
while true; do
read -p "Enter the number of the SOURCE profile to copy from: " src_idx
if [[ "$src_idx" =~ ^[0-9]+$ ]] && [ "$src_idx" -ge 1 ] && [ "$src_idx" -le "${#profile_dirs[@]}" ]; then
src_idx=$((src_idx-1))
break
else
echo "Invalid selection. Please enter a valid number."
fi
done
# Prompt for destination profile
while true; do
read -p "Enter the number of the DESTINATION profile to copy to: " dst_idx
if [[ "$dst_idx" =~ ^[0-9]+$ ]] && [ "$dst_idx" -ge 1 ] && [ "$dst_idx" -le "${#profile_dirs[@]}" ] && [ "$dst_idx" -ne "$((src_idx+1))" ]; then
dst_idx=$((dst_idx-1))
break
else
echo "Invalid selection. Please enter a valid number (and not the same as source)."
fi
done
echo "Backing up destination Bookmarks file to $dst_bookmarks.bak"
echo cp -f "$src_bookmarks" "$dst_bookmarks"
src_profile="${profile_dirs[$src_idx]}"
dst_profile="${profile_dirs[$dst_idx]}"
# Copy Bookmarks file
src_bookmarks="$src_profile/Bookmarks"
dst_bookmarks="$dst_profile/Bookmarks"
if [ ! -f "$src_bookmarks" ]; then
echo "Source Bookmarks file not found: $src_bookmarks"
exit 1
fi
# Show top 10 bookmark names from source
echo "\nPreview of top 10 bookmarks in source profile:"
grep -o '"name" *: *"[^"]*"' "$src_bookmarks" | sed 's/.*: *"\([^"]*\)"/\1/' | head -10 | nl
echo ""
read -p "Are these the bookmarks you want to copy? (y/n): " confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
echo "Aborted. No files were copied."
exit 0
fi
echo "Backing up destination Bookmarks file to $dst_bookmarks.bak"
cp -f "$dst_bookmarks" "$dst_bookmarks.bak"
cp -f "$src_bookmarks" "$dst_bookmarks"
echo "Copied Bookmarks from $(basename "$src_profile") to $(basename "$dst_profile")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment