Skip to content

Instantly share code, notes, and snippets.

@philc
Created July 21, 2014 01:05
Show Gist options
  • Save philc/e849b48e6c5f32592d62 to your computer and use it in GitHub Desktop.
Save philc/e849b48e6c5f32592d62 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.
# Location of Chromium's 'Web Data' SQLite3 file
CHROMIUM_WEB_DATA="$HOME/.config/chromium/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"
@smblott-github
Copy link

If you use Chrome instead of Chromium, then you may have to replace...

CHROMIUM_WEB_DATA="$HOME/.config/chromium/Default/Web Data"

with...

CHROMIUM_WEB_DATA="$HOME/.config/google-chrome/Default/Web Data"

@fhchl
Copy link

fhchl commented Mar 10, 2017

On Windows using Chrome, you can set the path to

CHROMIUM_WEB_DATA="C:\Users\[username]\AppData\Local\Google\Chrome\User Data\Default\Web Data"

You'll probably need sql3lite. You can just put these somewhere into your path.

@ijoseph
Copy link

ijoseph commented Sep 4, 2018

I had to mess around with the sqlite3 meta-commands to get this to work with my custom ~/.sqliterc. Please consider updating from my fork.

@neo-sam
Copy link

neo-sam commented Aug 4, 2020

Thanks! ❤

By the way, it works on windows chromium edge browser by git bash, following this path:

CHROMIUM_WEB_DATA="$HOME\AppData\Local\Microsoft\Edge\User Data\Default\Web Data"

@xatier
Copy link

xatier commented Mar 13, 2022

Similar to @ijoseph 's fork, I'm using awk to do the same. 😄

#!/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.

# Location of Chromium's 'Web Data' SQLite3 file
CHROMIUM_WEB_DATA="$HOME/.config/microsoft-edge-dev/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
select keyword, url, short_name 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
' |
awk -v FS='|' '{ print $1": "$2"  "$3}'
rm "$COPY"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment