├── .gitignore
├── .travis.yml
├── LICENSE
├── css
└── preview.css
├── package.json
├── readme.md
├── snip.svg
├── src
├── delete.js
├── deleteSnippet.js
├── lib
│ └── snippets.js
├── read.js
├── write.js
└── writeSnippet.js
├── test
├── cacheSnippets.js
└── index.js
└── zazu.json
/.gitignore:
--------------------------------------------------------------------------------
1 | snippets
2 | node_modules
3 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 |
3 | node_js:
4 | - 6
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | This is free and unencumbered software released into the public domain.
2 |
3 | Anyone is free to copy, modify, publish, use, compile, sell, or
4 | distribute this software, either in source code form or as a compiled
5 | binary, for any purpose, commercial or non-commercial, and by any
6 | means.
7 |
8 | In jurisdictions that recognize copyright laws, the author or authors
9 | of this software dedicate any and all copyright interest in the
10 | software to the public domain. We make this dedication for the benefit
11 | of the public at large and to the detriment of our heirs and
12 | successors. We intend this dedication to be an overt act of
13 | relinquishment in perpetuity of all present and future rights to this
14 | software under copyright law.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 | OTHER DEALINGS IN THE SOFTWARE.
23 |
24 | For more information, please refer to
${htmlEncode(result.value)}71 | 72 | ` 73 | } 74 | }) 75 | } 76 | 77 | delete (name) { 78 | delete this.index[name] 79 | const filePath = path.join(this.snippetDir, name) 80 | fs.unlink(filePath, function (err) { 81 | if (err) return this.console.log('warn', err) 82 | }) 83 | } 84 | } 85 | 86 | var singleton = null 87 | module.exports = (console, env={}) => { 88 | return singleton || (singleton = new Snippets(console, env)) 89 | } 90 | -------------------------------------------------------------------------------- /src/read.js: -------------------------------------------------------------------------------- 1 | module.exports = (pluginContext) => { 2 | return (query, env = {}) => { 3 | const { cwd, console } = pluginContext 4 | const snippets = require('./lib/snippets')(console, env) 5 | return new Promise((resolve, reject) => { 6 | const results = snippets.search(query) 7 | resolve(results ? results : []) 8 | }) 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/write.js: -------------------------------------------------------------------------------- 1 | module.exports = (pluginContext) => { 2 | return (key, env = {}) => { 3 | return new Promise((resolve, reject) => { 4 | resolve([{ 5 | id: key, 6 | title: `Create snippet called "${key}"`, 7 | value: key, 8 | }]) 9 | }) 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /src/writeSnippet.js: -------------------------------------------------------------------------------- 1 | module.exports = (pluginContext) => { 2 | return (name, env = {}) => { 3 | const { console } = pluginContext 4 | const snippets = require('./lib/snippets')(console, env) 5 | const content = pluginContext.clipboard.readText() 6 | snippets.create(name, content) 7 | return Promise.resolve() 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /test/cacheSnippets.js: -------------------------------------------------------------------------------- 1 | const describe = require('tape') 2 | const Snippets = require('../src/lib/snippets') 3 | 4 | const snippets = Snippets(__dirname, { log: () => {} }) 5 | 6 | describe('search for major items', (assert) => { 7 | assert.plan(1) 8 | 9 | snippets.index = { 10 | 'migrations': 'foo', 11 | 'rails_migrations': 'bar', 12 | 'work_email': 'princess@tinytacoteam.github.io', 13 | } 14 | 15 | const results = snippets.search('migrations') 16 | assert.ok(results.length === 2) 17 | }) 18 | 19 | describe('search for minor items', (assert) => { 20 | assert.plan(1) 21 | 22 | snippets.index = { 23 | 'migrations': 'foo', 24 | 'rails_migrations': 'bar', 25 | 'work_email': 'princess@tinytacoteam.github.io', 26 | } 27 | 28 | const results = snippets.search('work') 29 | assert.ok(results.length === 1) 30 | }) 31 | 32 | describe('search for no items', (assert) => { 33 | assert.plan(1) 34 | 35 | snippets.index = { 36 | 'migrations': 'foo', 37 | 'rails_migrations': 'bar', 38 | 'work_email': 'princess@tinytacoteam.github.io', 39 | } 40 | 41 | const results = snippets.search('meow') 42 | assert.ok(results.length === 0) 43 | }) 44 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | require('./cacheSnippets') 2 | -------------------------------------------------------------------------------- /zazu.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Zazu Snippets", 3 | "icon": "snip.svg", 4 | "stylesheet": "css/preview.css", 5 | "blocks": { 6 | "input": [ 7 | { 8 | "id": "Read", 9 | "type": "PrefixScript", 10 | "prefix": "snip", 11 | "space": true, 12 | "args": "Required", 13 | "script": "src/read.js", 14 | "connections": [ 15 | "Copy" 16 | ] 17 | }, 18 | { 19 | "id": "Write", 20 | "type": "PrefixScript", 21 | "prefix": "snipc", 22 | "space": true, 23 | "args": "Required", 24 | "script": "src/write.js", 25 | "connections": [ 26 | "WriteSnippet" 27 | ] 28 | }, 29 | { 30 | "id": "Delete", 31 | "type": "PrefixScript", 32 | "prefix": "snipd", 33 | "space": true, 34 | "args": "Required", 35 | "script": "src/delete.js", 36 | "connections": [ 37 | "DeleteSnippet" 38 | ] 39 | } 40 | ], 41 | "output": [ 42 | { 43 | "id": "Copy", 44 | "type": "CopyToClipboard", 45 | "text": "{value}" 46 | }, 47 | { 48 | "id": "WriteSnippet", 49 | "type": "UserScript", 50 | "script": "src/writeSnippet.js", 51 | "value": "{value}" 52 | }, 53 | { 54 | "id": "DeleteSnippet", 55 | "type": "UserScript", 56 | "script": "src/deleteSnippet.js", 57 | "value": "{value}" 58 | } 59 | ], 60 | "external": [ 61 | { 62 | "id": "Direct", 63 | "type": "Hotkey", 64 | "hotkey": "CmdOrCtrl+Alt+Space", 65 | "connections": [ "Write" ] 66 | } 67 | ] 68 | } 69 | } 70 | --------------------------------------------------------------------------------