├── congee ├── README.md ├── congee-clear.js ├── congee.js ├── package.json ├── congee-remove.js ├── congee-find.js ├── congee-list.js ├── congee-get.js └── congee-put.js ├── .gitignore ├── README.md └── LICENSE /congee/README.md: -------------------------------------------------------------------------------- 1 | # congee 2 | A local key-value store for terminal commands and more 3 | -------------------------------------------------------------------------------- /congee/congee-clear.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | // Load modules 4 | var program = require('commander'); 5 | var chalk = require('chalk'); 6 | var sqlite3 = require('sqlite3').verbose(); 7 | 8 | program 9 | .parse(process.argv); 10 | 11 | // List logic 12 | var db = new sqlite3.Database('congee.db'); 13 | db.serialize(function() { 14 | db.run("CREATE TABLE if not exists congee (key TEXT PRIMARY KEY, value TEXT)"); 15 | db.run("DELETE FROM congee"); 16 | 17 | console.log("All values removed from congee!"); 18 | }); 19 | db.close(); 20 | -------------------------------------------------------------------------------- /congee/congee.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | // Load modules 4 | var program = require('commander'); 5 | var chalk = require('chalk'); 6 | 7 | // Print program information 8 | program 9 | .version('0.0.4') 10 | .command('list', 'List all available commands') 11 | .command('find [query]', 'Search saved commands by keyword') 12 | .command('get [key]', 'Get a command by a plaintext key') 13 | .command('put [key] [command]', 'Save a command mapped to a plaintext key') 14 | .command('remove [key]', 'Remove a command by a plaintext key') 15 | .command('clear', 'Delete all key value pairs stored') 16 | .parse(process.argv); 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | 35 | # Local files 36 | congee/config.json 37 | congee/congee.db 38 | -------------------------------------------------------------------------------- /congee/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "congee", 3 | "version": "0.0.4", 4 | "description": "A local plaintext key-value store for terminal commands and more", 5 | "main": "congee.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/sup/congee.git" 12 | }, 13 | "keywords": [ 14 | "cli", 15 | "history", 16 | "alias", 17 | "commands", 18 | "developers" 19 | ], 20 | "author": "Charles Lai ", 21 | "license": "MIT", 22 | "bin": { 23 | "congee": "./congee.js" 24 | }, 25 | "bugs": { 26 | "url": "https://github.com/sup/congee/issues" 27 | }, 28 | "homepage": "https://github.com/sup/congee#readme", 29 | "dependencies": { 30 | "chalk": "^1.1.3", 31 | "commander": "^2.9.0", 32 | "readline-sync": "^1.4.1", 33 | "sqlite3": "^3.1.4", 34 | "superagent": "^1.8.3" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /congee/congee-remove.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | // Load modules 4 | var program = require('commander'); 5 | var chalk = require('chalk'); 6 | var sqlite3 = require('sqlite3').verbose(); 7 | 8 | program 9 | .parse(process.argv); 10 | 11 | // Get and validate keys array 12 | var keys = program.args; 13 | 14 | // Raise exception if no keys provided 15 | if (!keys.length) { 16 | console.error("Key required to get associated value!"); 17 | process.exit(1); 18 | } 19 | // Raise exception if more than one key provided 20 | if (keys.length > 1) { 21 | console.error("Can't delete more than one key value pair at a time!"); 22 | process.exit(1); 23 | } 24 | 25 | // List logic 26 | var db = new sqlite3.Database('congee.db'); 27 | db.serialize(function() { 28 | db.run("CREATE TABLE if not exists congee (key TEXT PRIMARY KEY, value TEXT)"); 29 | db.run("DELETE FROM congee WHERE key='" + keys[0] + "'"); 30 | 31 | console.log(keys[0] + " removed from congee!"); 32 | }); 33 | db.close(); 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # congee (WIP) 2 | [![NPM Version][npm-image]][npm-url] 3 | 4 | A local plaintext key-value store for terminal commands and more 5 | 6 | 7 | 8 | 9 | # Why 10 | * Some commands are long and hard to remember 11 | * Aliases are annoying to set and remove 12 | * Grepping history is annoying to do 13 | * Hashmap/Dict API is nice 14 | * You can store cool smiley faces wow 15 | * Anything ur heart desires really 16 | 17 | ## Install 18 | 19 | ```bash 20 | npm install -g congee 21 | ``` 22 | 23 | ## Usage 24 | 25 | TODO 26 | 27 | ## License 28 | 29 | [MIT](LICENSE) 30 | 31 | [npm-image]: https://img.shields.io/npm/v/congee.svg 32 | [npm-url]: https://npmjs.org/package/congee 33 | [travis-image]: https://img.shields.io/travis/live-js/live-xxx/master.svg 34 | [travis-url]: https://travis-ci.org/live-js/live-xxx 35 | [coveralls-image]: https://img.shields.io/coveralls/live-js/live-xxx/master.svg 36 | [coveralls-url]: https://coveralls.io/r/live-js/live-xxx?branch=master 37 | -------------------------------------------------------------------------------- /congee/congee-find.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | // Load modules 4 | var program = require('commander'); 5 | var chalk = require('chalk'); 6 | var sqlite3 = require('sqlite3').verbose(); 7 | 8 | program 9 | .option('-t, --type [key|value]', 'Search for key value pairs by key or value', /^(key|value)$/i) 10 | .parse(process.argv); 11 | 12 | // List logic 13 | var db = new sqlite3.Database('congee.db'); 14 | db.serialize(function() { 15 | db.run("CREATE TABLE if not exists congee (key TEXT PRIMARY KEY, value TEXT)"); 16 | 17 | // Create select statement to return stored values 18 | var select_statement = "SELECT rowid AS id, key, value FROM congee "; 19 | else if (program.sort == "key") { 20 | select_statement = select_statement + "ORDER BY key ASC"; 21 | } 22 | else if (program.sort == "value") { 23 | select_statement = select_statement + "ORDER BY value ASC"; 24 | } 25 | // Display each key-value pair in congee 26 | db.each(select_statement, function(err, row) { 27 | console.log(chalk.blue(row.key) + " " + chalk.green(row.value)); 28 | }); 29 | }); 30 | db.close(); 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Charles Lai 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /congee/congee-list.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | // Load modules 4 | var program = require('commander'); 5 | var chalk = require('chalk'); 6 | var sqlite3 = require('sqlite3').verbose(); 7 | 8 | program 9 | .option('-s, --sort [created|key|value]', 'Sort key value pairs by various attributes', /^(created|key|value)$/i) 10 | .parse(process.argv); 11 | 12 | // List logic 13 | var db = new sqlite3.Database('congee.db'); 14 | db.serialize(function() { 15 | db.run("CREATE TABLE if not exists congee (key TEXT PRIMARY KEY, value TEXT)"); 16 | 17 | // Create select statement to return stored values 18 | var select_statement = "SELECT rowid AS id, key, value FROM congee "; 19 | if (program.sort == "created") { 20 | select_statement = select_statement + "ORDER BY id ASC"; 21 | } 22 | else if (program.sort == "key") { 23 | select_statement = select_statement + "ORDER BY key ASC"; 24 | } 25 | else if (program.sort == "value") { 26 | select_statement = select_statement + "ORDER BY value ASC"; 27 | } 28 | // Display each key-value pair in congee 29 | db.each(select_statement, function(err, row) { 30 | console.log(chalk.blue(row.key) + ": " + chalk.green(row.value)); 31 | }); 32 | }); 33 | db.close(); 34 | -------------------------------------------------------------------------------- /congee/congee-get.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | // Load modules 4 | var program = require('commander'); 5 | var chalk = require('chalk'); 6 | var sqlite3 = require('sqlite3').verbose(); 7 | var exec = require('child_process').exec; 8 | 9 | // Parse argument vector 10 | program 11 | .option('-r, --run', 'Get and run a retrieved command in shell (no output)') 12 | .parse(process.argv); 13 | 14 | // Get and validate keys array 15 | var keys = program.args; 16 | 17 | // Raise exception if no keys provided 18 | if (!keys.length) { 19 | console.error("Key required to get associated value!"); 20 | process.exit(1); 21 | } 22 | // Raise exception if more than one key provided 23 | if (keys.length > 1) { 24 | console.error("Can't provide more than one key at a time!"); 25 | process.exit(1); 26 | } 27 | 28 | // Get logic 29 | var db = new sqlite3.Database('congee.db'); 30 | db.serialize(function() { 31 | db.run("CREATE TABLE if not exists congee (key TEXT PRIMARY KEY, value TEXT)"); 32 | 33 | // Create select statement to return stored values 34 | var select_statement = "SELECT rowid AS id, key, value \ 35 | FROM congee WHERE key='" + keys[0] + "'"; 36 | 37 | // Handle value returned 38 | db.each(select_statement, function(err, row) { 39 | console.log(chalk.green(row.value)); 40 | // If run option is specified, run the execute the returned value 41 | if (program.run) { 42 | exec(row.value, function(error, stdout, stderr) { 43 | // TODO: Callback and output 44 | 45 | }); 46 | } 47 | }); 48 | }); 49 | db.close(); 50 | -------------------------------------------------------------------------------- /congee/congee-put.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | // Load modules 4 | var program = require('commander'); 5 | var chalk = require('chalk'); 6 | var sqlite3 = require('sqlite3').verbose(); 7 | 8 | // Parse argument vector 9 | program 10 | .parse(process.argv); 11 | 12 | // Get and validate keys array 13 | var key_value = program.args; 14 | // Raise exception if nothing provided 15 | if (!key_value.length) { 16 | console.error("Key required to get associated value!"); 17 | process.exit(1); 18 | } 19 | // Raise exception if no value provided 20 | if (key_value.length == 1) { 21 | console.error("Value required to put a key value pair!"); 22 | process.exit(1); 23 | } 24 | // Raise exception if more than one key value pair provided 25 | if (key_value.length > 2) { 26 | console.error("Can't provide more than one key value pair at a time!"); 27 | process.exit(1); 28 | } 29 | 30 | // Put logic 31 | var db = new sqlite3.Database('congee.db'); 32 | var key = key_value[0] 33 | var value = key_value[1] 34 | db.serialize(function() { 35 | db.run("CREATE TABLE if not exists congee (key TEXT PRIMARY KEY, value TEXT)"); 36 | 37 | // Run insert/update statement to insert or override k-v pair 38 | var insert_statement = "INSERT OR IGNORE INTO congee(key, value) \ 39 | VALUES ('" + key + "', '" + value + "'); \ 40 | UPDATE congee SETS value='" + value + "' \ 41 | WHERE key='" + key + "'"; 42 | db.run(insert_statement); 43 | 44 | // Print confirmation message 45 | console.log("Key: " + chalk.blue(key) + " associated with value: " + chalk.green(value)); 46 | 47 | }); 48 | db.close(); 49 | --------------------------------------------------------------------------------