Skip to content

Instantly share code, notes, and snippets.

@harizvi
Forked from philc/gist:e849b48e6c5f32592d62
Last active September 13, 2021 21:57
Show Gist options
  • Save harizvi/405b1b0531111a6c3bf70ed05056001f to your computer and use it in GitHub Desktop.
Save harizvi/405b1b0531111a6c3bf70ed05056001f to your computer and use it in GitHub Desktop.
A script to copy Chrome's search engine settings into Vimium's settings format
#!/bin/sh
# This script lists user defined search engines in Chromium.
# It replaces {inputEncoding}, which appears in some search engine definitions, with
# UTF-8, {google:baseURL} with the Google URL, and omits other such tokens.
# can take browser name as first argument.
# 'Google Chrome', Chromium, BraveSoftware/Brave-Browser
browser=${1:-Vivaldi}
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
basedir="$HOME/.config"
elif [[ "$OSTYPE" == "darwin"* ]]; then
basedir="$HOME/Library/Application Support"
fi
# Location of browser's 'Web Data' SQLite3 file
CHROMIUM_WEB_DATA="$basedir/$browser/Default/Web Data"
# Location to create temporary copy of 'Web Data', since the database is locked while
# Chromium is running
COPY=$(mktemp)
cp "$CHROMIUM_WEB_DATA" "$COPY"
sqlite3 <<COMMANDS "$COPY" |
.echo off
.separator ': '
select keyword, url from keywords;
.quit
COMMANDS
sed -e \ '
s#{searchTerms}#%s#g
s#{google:baseURL}#https://google.com/#g
s#{inputEncoding}#UTF-8#g
s#&?[^{}?&]\+={[^}]\+}##g
s#{[^}]\+}##g
'
rm "$COPY"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment