├── .gitignore ├── LICENSE ├── README.md ├── gifs ├── demo.gif ├── gistpush.gif └── multiple-gist-support.gif ├── index.js ├── package.json ├── success.js └── test └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Shubham Rath 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 |
2 | 3 | [![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/sr6033/gistpush)   [![NPM](https://nodei.co/npm/gistpush.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/gistpush/)   [![GitHub](https://img.shields.io/badge/node-%3E%3D6.0.0-blue.svg)]() 4 | 5 |
6 | 7 |
8 | gistpush 13 | gistpush now supports multiple gist uploads 17 |
18 | 19 | > Add your files/content to gist easily with a single command. 20 | 21 | Now there is no need for you to open up your gist/github account to upload a gist. Just write your code/content in a file and name the file as you would in the gist. Then upload it to your account as publicly or privately accessible using the command line. 22 | 23 | ## Installation 24 | 25 | `npm i --global gistpush` 26 | 27 | ## Usage 28 | 29 | Run `gistpush ` 30 | 31 | > Supports multiple gists upload: `gistpush ...` 32 | 33 |

34 | demo of gistpush 35 |

36 | 37 | For help, run: `gistpush -h` 38 | 39 | ## Contributing 40 | 41 | I am open to both suggestions and help. So feel free to pull up an issue or send in a PR with additional features or enhancements. 42 | 43 | - Fork the repo 44 | - Clone your forked repo and install dependencies: `npm install` 45 | - Edit the **index.js** file or add additional files. 46 | 47 | ## To do 48 | 49 | - [ ] Add edit & delete gists options 50 | - [x] Make password invisible 51 | - [ ] Remove unwanted space while typing text 52 | - [ ] Update gif 53 | 54 | :star: the repo if you liked it. 55 | 56 | Made with :blue_heart: :heavy_plus_sign: :coffee:. 57 | Gifs were made using ![Giphy](https://giphy.com/) and ![Recordit](http://recordit.co/). 58 | -------------------------------------------------------------------------------- /gifs/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sr6033/gistpush/0e3cac794d4978df56482881304e3a8bd7924afd/gifs/demo.gif -------------------------------------------------------------------------------- /gifs/gistpush.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sr6033/gistpush/0e3cac794d4978df56482881304e3a8bd7924afd/gifs/gistpush.gif -------------------------------------------------------------------------------- /gifs/multiple-gist-support.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sr6033/gistpush/0e3cac794d4978df56482881304e3a8bd7924afd/gifs/multiple-gist-support.gif -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const Gists = require('gists'); 3 | const fs = require('fs'); 4 | //const ProgressBar = require('progress'); 5 | const chalk = require('chalk'); 6 | const request = require('superagent'); 7 | const co = require('co'); 8 | //const prompt = require('co-prompt'); 9 | const program = require('commander'); 10 | const terminalLink = require('terminal-link'); 11 | const exit = require('./success.js'); 12 | const prompt = require('prompt-sync')(); // Sync cli input 13 | var CLI = require('clui'), 14 | Spinner = CLI.Spinner; 15 | 16 | var username = '', password = '', details = [], privacy = [], 17 | upload_complete = false; 18 | 19 | /* 20 | // Using promise (async) 21 | function input_data(fileList) { 22 | return new Promise(function(resolve, reject) { 23 | // Do async job 24 | co(function *() { 25 | username = yield prompt(chalk.yellow('username: ')); 26 | password = yield prompt.password(chalk.yellow('password: ')); 27 | 28 | for(file of fileList) 29 | { 30 | console.log('for file: ' + chalk.cyan(file)); 31 | var detail_text = yield prompt(chalk.yellow('description: ')); 32 | var privacy_value = yield prompt(chalk.yellow('access [Public(t)/Private(f)]: ')); 33 | details.push(detail_text); 34 | privacy.push(privacy_value); 35 | } 36 | }); 37 | resolve(true); 38 | }) 39 | } 40 | */ 41 | 42 | // Using sync command line input 43 | function input_data(fileList) { 44 | username = prompt(chalk.yellow('username: ')); 45 | password = prompt.hide(chalk.yellow('password: ')); 46 | 47 | for(file of fileList) 48 | { 49 | console.log('for file: ' + chalk.cyan(file)); 50 | var detail_text = prompt(chalk.yellow('description: ')); 51 | var privacy_value = prompt(chalk.yellow('access [Public(t)/Private(f)]: ')); 52 | details.push(detail_text); 53 | privacy.push(privacy_value); 54 | } 55 | 56 | return true; 57 | } 58 | 59 | function loading() { 60 | var countdown = new Spinner('Uploading... ', ['⣾','⣽','⣻','⢿','⡿','⣟','⣯','⣷']); 61 | 62 | console.log('Uploading... '); 63 | countdown.start() 64 | 65 | // var number = 10; 66 | setInterval(function () { 67 | // number--; 68 | // countdown.message('Uploading... '); 69 | 70 | if (upload_complete) { 71 | countdown.stop(); 72 | process.stdout.write('\n'); 73 | process.exit(0); 74 | } 75 | }, 1000); 76 | } 77 | 78 | function main() { 79 | program 80 | .arguments(' [file2]') 81 | .option('-u, --username ', 'The user to authenticate as') 82 | .option('-p, --password ', 'The user\'s password') 83 | .option('-d, --description ', 'Description of the file') 84 | .option('-a, --access ', 'Public(t)/Private(f) access for the file. Default is true.') 85 | //.option('-c, --collect [value]', 'A repeatable value', collect, []) 86 | //.option('-f, --multipleFiles ', 't: multiple files | default: single file') 87 | 88 | .action(function() { 89 | //console.log(' collect: %j', program.collect); 90 | 91 | var count_upload = 0; 92 | 93 | co(function *() { 94 | //console.log(program.args); 95 | var fileList = [], links = []; 96 | fileList = program.args[2]['rawArgs'].filter( function(val, index) { 97 | if(index > 1) 98 | return true; 99 | }); 100 | 101 | // Taking inputs 102 | var success = false; 103 | success = input_data(fileList); 104 | 105 | // After sync input is complete 106 | if(success == true) 107 | { 108 | loading(); // Loading animation 109 | 110 | var fileNumber = 0; 111 | for(var file of fileList) 112 | { 113 | var description = details[fileNumber]; 114 | var access = privacy[fileNumber]; 115 | 116 | if(access == 't' || access == 'true') 117 | access = true; 118 | else 119 | if(access == 'f' || access == 'false') 120 | access = false; 121 | else 122 | access = true; 123 | 124 | const gists = new Gists({ 125 | username: username, 126 | password: password 127 | }); 128 | 129 | var fileData = fs.readFileSync(file, 'utf8'); 130 | 131 | ++fileNumber; 132 | 133 | gists.create( 134 | { 135 | "description": description, 136 | "public": access, 137 | "files": { 138 | [file]: { 139 | "content": fileData 140 | } 141 | } 142 | } 143 | ) 144 | .then(function(res, err) { 145 | if(res) 146 | { 147 | const url = terminalLink(res.body.html_url, res.body.html_url); 148 | links.push(url); 149 | ++count_upload; 150 | 151 | // Checking end of all file uploads 152 | if(count_upload == fileList.length) 153 | { 154 | upload_complete = true; 155 | exit(true, links, fileList); 156 | } 157 | } 158 | }) 159 | .catch(function(err) { 160 | console.log(chalk.red(err)); 161 | process.exit(1); 162 | }); 163 | 164 | } // end for 165 | } // end if 166 | 167 | 168 | }); 169 | }) 170 | .parse(process.argv); 171 | 172 | } 173 | 174 | 175 | main(); 176 | module.exports = main; 177 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gistpush", 3 | "version": "2.0.2", 4 | "description": "CLI tool to create, remove & manipulate github gists.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha" 8 | }, 9 | "keywords": [ 10 | "cli", 11 | "gist" 12 | ], 13 | "author": "Shubham Rath", 14 | "license": "ISC", 15 | "bin": { 16 | "gistpush": "./index.js" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "https://github.com/sr6033/gistpush" 21 | }, 22 | "dependencies": { 23 | "chalk": "^2.4.1", 24 | "clui": "^0.3.6", 25 | "co": "^4.6.0", 26 | "co-prompt": "^1.0.0", 27 | "commander": "^2.18.0", 28 | "gists": "^2.0.0", 29 | "progress": "^2.0.0", 30 | "prompt-sync": "^4.1.6", 31 | "superagent": "^3.8.3", 32 | "terminal-link": "^1.1.0" 33 | }, 34 | "devDependencies": { 35 | "chai": "^4.2.0", 36 | "mocha": "^5.2.0" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /success.js: -------------------------------------------------------------------------------- 1 | const chalk = require('chalk'); 2 | 3 | function exit(check_end, links, fileList) { 4 | if(check_end == true) 5 | { 6 | console.log(chalk.cyan('\nGist(s) added successfully.')); 7 | var index = 0; 8 | for(val of links) 9 | console.log(chalk.green(fileList[index++] + ': ' + val + '\n')); 10 | process.exit(0); 11 | } 12 | } 13 | 14 | module.exports = exit; -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | const expect = require('chai').expect; 2 | const main = require('../main'); 3 | const exit = require('../success.js'); 4 | 5 | describe('main()', function() { 6 | it('should accept credentials, file name & details and return the link to gist(s)', function() { 7 | 8 | }); 9 | }); --------------------------------------------------------------------------------