1
0
Fork 0
mirror of synced 2024-06-16 17:35:15 +12:00

add chrome and firefox bookmarks export to history script

This commit is contained in:
Nick Sweeting 2020-08-18 00:36:46 -04:00 committed by GitHub
parent 26022fc9fb
commit ec4db1f75e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,21 +1,22 @@
#!/bin/bash #!/bin/bash
REPO_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )" OUTPUT_DIR="$(pwd)"
mkdir -p "$REPO_DIR/output/sources"
if [[ "$1" == "--chrome" ]]; then if [[ "$1" == "--chrome" ]]; then
# Google Chrome / Chromium # Google Chrome / Chromium
if [[ -e "$2" ]]; then if [[ -e "$2" ]]; then
cp "$2" "$REPO_DIR/output/sources/chrome_history.db.tmp" cp "$2" "$OUTPUT_DIR/chrome_history.db.tmp"
else else
default=$(ls ~/Library/Application\ Support/Google/Chrome/Default/History) default=$(ls ~/Library/Application\ Support/Google/Chrome/Default/History)
echo "Defaulting to history db: $default" echo "Defaulting to history db: $default"
echo "Optionally specify the path to a different sqlite history database as the 2nd argument." echo "Optionally specify the path to a different sqlite history database as the 2nd argument."
cp "$default" "$REPO_DIR/output/sources/chrome_history.db.tmp" cp "$default" "$OUTPUT_DIR/chrome_history.db.tmp"
fi fi
sqlite3 "$REPO_DIR/output/sources/chrome_history.db.tmp" "SELECT \"[\" || group_concat(json_object('timestamp', last_visit_time, 'description', title, 'href', url)) || \"]\" FROM urls;" > "$REPO_DIR/output/sources/chrome_history.json"
rm "$REPO_DIR"/output/sources/chrome_history.db.* sqlite3 "$OUTPUT_DIR/chrome_history.db.tmp" "SELECT \"[\" || group_concat(json_object('timestamp', last_visit_time, 'description', title, 'href', url)) || \"]\" FROM urls;" > "$OUTPUT_DIR/chrome_history.json"
jq < "$(dirname "${2:-$default}")"/Bookmarks '.roots.other.children[] | {href: .url, description: .name, timestamp: .date_added}' > "$OUTPUT_DIR/chrome_bookmarks.json"
rm "$DATA_DIR"/output/sources/chrome_history.db.*
echo "Chrome history exported to:" echo "Chrome history exported to:"
echo " output/sources/chrome_history.json" echo " output/sources/chrome_history.json"
fi fi
@ -23,31 +24,37 @@ fi
if [[ "$1" == "--firefox" ]]; then if [[ "$1" == "--firefox" ]]; then
# Firefox # Firefox
if [[ -e "$2" ]]; then if [[ -e "$2" ]]; then
cp "$2" "$REPO_DIR/output/sources/firefox_history.db.tmp" cp "$2" "$OUTPUT_DIR/firefox_history.db.tmp"
else else
default=$(ls ~/Library/Application\ Support/Firefox/Profiles/*.default/places.sqlite) default=$(ls ~/Library/Application\ Support/Firefox/Profiles/*.default/places.sqlite)
echo "Defaulting to history db: $default" echo "Defaulting to history db: $default"
echo "Optionally specify the path to a different sqlite history database as the 2nd argument." echo "Optionally specify the path to a different sqlite history database as the 2nd argument."
cp "$default" "$REPO_DIR/output/sources/firefox_history.db.tmp" cp "$default" "$OUTPUT_DIR/firefox_history.db.tmp"
fi fi
sqlite3 "$REPO_DIR/output/sources/firefox_history.db.tmp" "SELECT \"[\" || group_concat(json_object('timestamp', last_visit_date, 'description', title, 'href', url)) || \"]\" FROM moz_places;" > "$REPO_DIR/output/sources/firefox_history.json"
rm "$REPO_DIR"/output/sources/firefox_history.db.* sqlite3 "$OUTPUT_DIR/firefox_history.db.tmp" "SELECT \"[\" || group_concat(json_object('timestamp', last_visit_date, 'description', title, 'href', url)) || \"]\" FROM moz_places;" > "$OUTPUT_DIR/firefox_history.json"
sqlite3 "$OUTPUT_DIR/firefox_history.db.tmp" "SELECT \"[\" || group_concat(json_object('timestamp', b.dateAdded, 'description', b.title, 'href', f.url)) || \"]\" FROM moz_bookmarks AS b JOIN moz_places AS f ON f.id = b.fk" > "$OUTPUT_DIR/firefox_bookmarks.json"
rm "$DATA_DIR"/output/sources/firefox_history.db.*
echo "Firefox history exported to:" echo "Firefox history exported to:"
echo " output/sources/firefox_history.json" echo " output/sources/firefox_history.json"
echo " output/sources/firefox_bookmarks.json"
fi fi
if [[ "$1" == "--safari" ]]; then if [[ "$1" == "--safari" ]]; then
# Safari # Safari
if [[ -e "$2" ]]; then if [[ -e "$2" ]]; then
cp "$2" "$REPO_DIR/output/sources/safari_history.db.tmp" cp "$2" "$OUTPUT_DIR/safari_history.db.tmp"
else else
default="~/Library/Safari/History.db" default="~/Library/Safari/History.db"
echo "Defaulting to history db: $default" echo "Defaulting to history db: $default"
echo "Optionally specify the path to a different sqlite history database as the 2nd argument." echo "Optionally specify the path to a different sqlite history database as the 2nd argument."
cp "$default" "$REPO_DIR/output/sources/safari_history.db.tmp" cp "$default" "$OUTPUT_DIR/safari_history.db.tmp"
fi fi
sqlite3 "$REPO_DIR/output/sources/safari_history.db.tmp" "select url from history_items" > "$REPO_DIR/output/sources/safari_history.json"
rm "$REPO_DIR"/output/sources/safari_history.db.* sqlite3 "$OUTPUT_DIR/safari_history.db.tmp" "select url from history_items" > "$OUTPUT_DIR/safari_history.json"
rm "$DATA_DIR"/output/sources/safari_history.db.*
echo "Safari history exported to:" echo "Safari history exported to:"
echo " output/sources/safari_history.json" echo " output/sources/safari_history.json"
fi fi