├── .gitignore ├── LICENSE ├── README.md ├── package.json └── src └── create.js /.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 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Surbhi Oberoi 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Gistifier - A command line tool 2 | 3 | Create a Gist from a set of file(s). 4 | 5 | 6 | ### Installation 7 | 8 | ``` 9 | npm install -g gistifier 10 | ``` 11 | 12 | 13 | ### How to use 14 | 15 | From your terminal go to the directory where your files reside and run, 16 | 17 | ``` bash 18 | $ gistifier push 19 | ``` 20 | 21 | To push all files in current directory top level 22 | 23 | ``` 24 | $ gistifier push 25 | ``` 26 | 27 | To make your Gist public 28 | 29 | ``` 30 | $ gisitifer push --public 31 | ``` 32 | 33 | OR 34 | 35 | ``` 36 | $ gisitifer push -p 37 | ``` 38 | 39 | 40 | ### Use Cases 41 | 42 | 1. Sharing multiple files quickly 43 | 2. Lightweight code review, as Gists can be commented upon. 44 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gistifier", 3 | "version": "1.1.0", 4 | "description": "Create a GitHub gist with your current directory contents", 5 | "main": "src/create.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Surbhi Oberoi (http://surbhioberoi.com/)", 10 | "license": "MIT", 11 | "dependencies": { 12 | "commander": "2.9.0", 13 | "open": "0.0.5", 14 | "request": "2.74.0" 15 | }, 16 | "preferGlobal": true, 17 | "bin": { 18 | "gistifier": "src/create.js" 19 | }, 20 | "devDependencies": {}, 21 | "repository": { 22 | "type": "git", 23 | "url": "git+https://github.com/surbhioberoi/gistifier.git" 24 | }, 25 | "keywords": [ 26 | "create", 27 | "gist", 28 | "gistifier", 29 | "upload" 30 | ], 31 | "bugs": { 32 | "url": "https://github.com/surbhioberoi/gistifier/issues" 33 | }, 34 | "homepage": "https://github.com/surbhioberoi/gistifier#readme" 35 | } 36 | -------------------------------------------------------------------------------- /src/create.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | 3 | var fs = require('fs'); 4 | var request = require('request'); 5 | var open = require('open'); 6 | var program = require('commander'); 7 | 8 | 9 | program.option('-p --public', 'Posts your Gist publicly. Defaults to secret if option is not included.') 10 | 11 | 12 | var fileNames = []; 13 | 14 | program 15 | .command('push [names...]') 16 | .description('Select the files you wish to push as Gist') 17 | .action(function(names) { 18 | if (names.length === 0) { 19 | fileNames = fs.readdirSync("./"); 20 | } else { 21 | fileNames = names; 22 | } 23 | createGist(); 24 | }) 25 | 26 | 27 | program.parse(process.argv); 28 | 29 | 30 | 31 | function getFiles(listOfFiles) { 32 | // This function returns an object which is as follows 33 | // { 34 | // : {'content': }, 35 | // : {'content': } 36 | // } 37 | 38 | var fileData = {}; 39 | 40 | for (var i = 0; i < listOfFiles.length; i++) { 41 | if (listOfFiles[i][0] != '.' && 42 | !fs.lstatSync(listOfFiles[i]).isDirectory()) { 43 | var fileContent = fs.readFileSync(listOfFiles[i]).toString(); 44 | if (fileContent) { 45 | fileData[listOfFiles[i]] = { "content": fileContent }; 46 | } 47 | } 48 | } 49 | return fileData; 50 | } 51 | 52 | 53 | function createGist() { 54 | var gistBody = { 55 | "description": "Exported using gistifier", 56 | "public": false, 57 | "files": getFiles(fileNames) 58 | } 59 | 60 | if (program.public) { 61 | gistBody.public = true; 62 | } 63 | 64 | var options = { 65 | uri: "https://api.github.com/gists", 66 | method: "POST", 67 | json: gistBody, 68 | headers: { 69 | "User-Agent": "Gistifier 1.0" 70 | } 71 | } 72 | 73 | request(options, function(error, response, body) { 74 | console.log('Your Gist has been created at ' + body.html_url); 75 | open(body.html_url); 76 | }) 77 | console.log('Creating your Gist...'); 78 | } 79 | --------------------------------------------------------------------------------