Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaine Schmeisser committed Jul 28, 2016
0 parents commit acc27df
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules
Binary file added assets/chrome.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions package.json
@@ -0,0 +1,17 @@
{
"name": "zazu-chrome-bookmarks",
"version": "1.0.0",
"description": "Chrome bookmark searcher for Zazu.",
"keywords": [
"zazu",
"search",
"chrome",
"bookmarks"
],
"author": "Blaine Schmeisser",
"license": "MIT",
"dependencies": {
"fuzzyfind": "^1.2.0",
"traverse": "^0.6.6"
}
}
28 changes: 28 additions & 0 deletions readme.md
@@ -0,0 +1,28 @@
## Chrome Bookmarks

Chrome bookmark searcher for Zazu.

## Installing

Add the package to your plugins array in `./zazurc.js`.

~~~ javascript
'tinytacoteam/zazu-chrome-bookmarks',
~~~

By default we look for your default profile located at:

~~~
/Users/bschmeisser/Library/Application Support/Google/Chrome/Default/Bookmarks
~~~

To overwrite it, set the `file` variable:

~~~ javascript
{
name: 'tinytacoteam/zazu-chrome-bookmarks',
variables: {
file: '~/Library/Application Support/Google/Chrome/Profile 1/Bookmarks',
},
}
~~~
38 changes: 38 additions & 0 deletions search.js
@@ -0,0 +1,38 @@
'use strict'
const fs = require('fs')
const os = require('os')
const traverse = require('traverse')
const fuzzyfind = require('fuzzyfind')

const file = '~/Library/Application Support/Google/Chrome/Default/Bookmarks'

module.exports = (pluginContext) => {
return (query, env) => {
const variables = env || {}
const bookmarkFile = (variables['file'] || file).replace(/^~/, os.homedir())
return new Promise((resolve, reject) => {
fs.readFile(bookmarkFile, (err, data) => {
const rawData = JSON.parse(data)
// Find
const bookmarks = []
traverse(rawData).forEach((item) => {
const isBookmark = item['type'] === 'url'
if (isBookmark) {
const bookmark = {
title: item['name'],
subtitle: item['url'],
value: item['url'],
}
bookmarks.push(bookmark)
}
})
// Filter
// toLowerCase() is required - https://github.com/amjith/fuzzyfind/pull/3
const filteredBookmarks = fuzzyfind(query.toLowerCase(), bookmarks, (bookmark) => {
return (bookmark.title + bookmark.subtitle).toLowerCase()
})
resolve(filteredBookmarks)
})
})
}
}
26 changes: 26 additions & 0 deletions zazu.js
@@ -0,0 +1,26 @@
module.exports = {
name: 'Chrome Bookmarks',
version: '1.0.0',
description: 'Chrome bookmark searcher for Zazu.',
icon: 'assets/chrome.png',
blocks: {
input: [
{
id: 'search',
type: 'PrefixScript',
space: true,
args: 'Required',
prefix: ',b',
script: 'search.js',
connections: ['Open'],
},
],
output: [
{
id: 'Open',
type: 'OpenInBrowser',
url: '{value}',
},
],
},
}

0 comments on commit acc27df

Please sign in to comment.