Skip to content

Instantly share code, notes, and snippets.

@craigbalding
Last active January 5, 2024 10:14
Show Gist options
  • Save craigbalding/2fa02f7e8161d6b8e2782fdb3f661740 to your computer and use it in GitHub Desktop.
Save craigbalding/2fa02f7e8161d6b8e2782fdb3f661740 to your computer and use it in GitHub Desktop.
Chrome profile history searcher & launcher for MacOS
crumber() {
# search_term is a URL fragment for a website you visited already, but can't remember in which chrome profile
search_term=$1
chrome_base_path=~/Library/Application\ Support/Google/Chrome
profile_dirs=$(ls "$chrome_base_path" | grep -E '^Default$|^Profile [0-9]+|^Guest Profile$')
# Create a temporary file to hold URL and profile pairs
tmpfile=$(mktemp)
echo "$profile_dirs" | while IFS= read -r profile; do
history_path="$chrome_base_path/$profile/History"
temp_history_path=$(mktemp)
# Create a temporary copy of the History database
if [ -f "$history_path" ]; then
cp "$history_path" "$temp_history_path"
# Query the history database and append profile info to each line
sqlite3 -readonly "$temp_history_path" "SELECT url FROM urls WHERE url LIKE '%$search_term%';" | \
while IFS= read -r url; do
echo "$url [$profile]" >> "$tmpfile"
done
# Remove the temporary database copy
rm "$temp_history_path"
fi
done
# debug: show the contents of the temporary file
# cat "$tmpfile"
# Use fzf to select a URL and extract the profile name
selection=$(cat "$tmpfile" | fzf --tiebreak=index --layout=reverse)
selected_profile=$(echo "$selection" | awk -F'[][]' '{print $2}')
selected_url=$(echo "$selection" | awk -F' ' '{print $1}')
# Open Chrome with the selected profile and URL
if [ -n "$selected_url" ]; then
open -na "Google Chrome" --args "--profile-directory=$selected_profile" "$selected_url"
fi
# Clean up the temporary file
rm "$tmpfile"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment