Skip to content

Instantly share code, notes, and snippets.

@chaifeng
Created October 26, 2023 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chaifeng/c7cba3f92424c3347fb6b473e1235666 to your computer and use it in GitHub Desktop.
Save chaifeng/c7cba3f92424c3347fb6b473e1235666 to your computer and use it in GitHub Desktop.
Generated by ChatGPT-4
#!/bin/bash
set -euo pipefail
TITLE="$1"
URL="$2"
DB_PATH="./places.sqlite"
PREFIX="${URL%%://*}://"
HOST="${URL#$PREFIX}"
HOST="${HOST%%/*}"
REV_HOST=$(echo $HOST | rev)
GUID=$(openssl rand -base64 9 | tr -d '+/=' | cut -c 1-12)
SQL_COMMAND="
INSERT INTO moz_origins (prefix, host, frecency)
SELECT '$PREFIX', '$HOST', -1
WHERE NOT EXISTS (SELECT 1 FROM moz_origins WHERE prefix='$PREFIX' AND host='$HOST');
PRAGMA foreign_keys=off;
INSERT INTO moz_places (url, title, rev_host, guid, origin_id)
VALUES ('$URL', '$TITLE', '$REV_HOST', '$GUID', (SELECT id FROM moz_origins WHERE host='$HOST' AND prefix='$PREFIX'));
PRAGMA foreign_keys=on;
INSERT INTO moz_bookmarks (type, fk, parent, position, title, guid, dateAdded, lastModified)
VALUES (1, (SELECT id FROM moz_places WHERE url='$URL'), 3, 0, '$TITLE', '$GUID', strftime('%s', 'now') * 1000000, strftime('%s', 'now') * 1000000);
"
echo "$SQL_COMMAND" | sqlite3 "$DB_PATH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment