Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[dist] 0.0.1

* first commit for the gold
  • Loading branch information...
commit b98e9ca0b78317cac68e311fba8611a2af24d17f 0 parents
@dscape authored
1  .gitignore
@@ -0,0 +1 @@
+node_modules
69 README.md
@@ -0,0 +1,69 @@
+# ghcopy
+
+dead simple way to copy paste your stdin to github
+
+## setup
+
+install [node]
+
+``` js
+$ npm install -g ghcopy
+$ ghcopy-authorize
+prompt: password: drsocketybearsocks
+prompt: password:
+{
+ "t": "sometoken"
+}
+```
+
+a file called `~/.ghcopy` containing your token was created. if you are not in windows the permissions have been set so only you can read and write on it. it does not store your username.
+
+if you are not comfortable with this you can create your token manually with curl and specify it each time you invoke ghcopy.
+
+## usage
+
+```
+cat ~/.ssh/id_rsa.pub | ghcopy
+```
+
+# contribute
+
+everyone is welcome to contribute. patches, bug-fixes, reporters, new features.
+
+1. create an [issue][issues] so the community can comment on your idea
+2. fork
+3. create a new branch `git checkout -b feature_name`
+4. create tests for the changes you made
+5. make sure you pass both existing and newly inserted tests
+6. commit your changes
+7. push to your branch `git push origin feature_name`
+8. create an pull request
+
+# meta
+
+* code: `git clone git://github.com/dscape/ghcopy.git`
+* home: <http://github.com/dscape/ghcopy>
+* bugs: <http://github.com/dscape/ghcopy/issues>
+
+`(oO)--',-` in [caos]
+
+<a name="license"/>
+# license
+
+copyright 2012 nuno job <nunojob.com> `(oO)--',--`
+
+licensed under the apache license, version 2.0 (the "license");
+you may not use this file except in compliance with the license.
+you may obtain a copy of the license at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+unless required by applicable law or agreed to in writing, software
+distributed under the license is distributed on an "as is" basis,
+without warranties or conditions of any kind, either express or implied.
+see the license for the specific language governing permissions and
+limitations under the license
+
+[node]: http://nodejs.org
+[issues]: http://github.com/dscape/ghcopy/issues
+[caos]: http://caos.di.uminho.pt/
100 bin/ghcopy
@@ -0,0 +1,100 @@
+#!/usr/bin/env node
+var request = require('request');
+var fs = require('fs');
+var path = require('path');
+var optimist = require('optimist');
+var url = require('url');
+var opener = require("opener");
+
+//
+// user home in a os agnostic way
+//
+var tilde =
+ process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'];
+
+var dotf = path.join(tilde, '.ghcopy');
+
+//
+// if options were not specified we need to check if the user has a .file
+// containing his credentials.
+//
+var opts_from_file = {};
+
+try {
+ var dotfile = JSON.parse(fs.readFileSync(dotf));
+ opts_from_file.t = dotfile.t;
+} catch (_) {
+ //
+ // Failed
+ //
+}
+
+
+var argv = optimist
+ .usage(
+ 'usage: cat ~/.ssh/id_rsa.pub | $0\n' +
+ 'hint : you can also define `t` in ~/.ghcopy\n' +
+ ' use $0-authorize to securely create a token for you')
+ .alias('d', 'description')
+ .describe('d', 'description for this gist')
+ ["default"]('d', 'gist created by github.com/dscape/ghcopy')
+ .alias('f', 'filename')
+ .describe('f', 'filename for the file pasted in this gist')
+ ["default"]('f', 'ghcopy.txt')
+ .alias('p', 'public')
+ .describe('p', 'boolean defining if this gist should be public or not')
+ .boolean(['p'])
+ ["default"]('p', false)
+ .alias('t', 'token')
+ .describe('t', 'define a github token')
+ ["default"]('t', opts_from_file.t)
+ .demand('t')
+ .argv
+ ;
+
+//
+// To buffer our data
+//
+var buffer = '';
+
+//
+// Our post to create a gist
+//
+var post =
+ { method : "POST"
+ , headers : {"Authorization": "bearer " + argv.t }
+ , uri : url.format(
+ { hostname : 'api.github.com'
+ , pathname : "/gists"
+ , protocol : "https"
+ })
+ , json:
+ { description : argv.d
+ , "public" : argv.p
+ , files : {}
+ }
+ };
+
+var stdin = process.openStdin();
+stdin.setEncoding('utf8');
+
+stdin.on('data', function (chunk) {
+ buffer += chunk;
+});
+
+stdin.on('end', function () {
+ post.json.files[argv.f] = {content: buffer};
+ request(post, function (err, _, body) {
+ if(err) {
+ console.log('Request failed with message: ' + err.message);
+ process.exit();
+ }
+ if(!body.html_url) {
+ console.log('Request failed: No url in body');
+ console.log(JSON.stringify(body, null, 2));
+ process.exit();
+ }
+ console.log(body.html_url);
+ opener(body.html_url);
+ });
+});
114 bin/ghcopy-authorize
@@ -0,0 +1,114 @@
+#!/usr/bin/env node
+var request = require('request');
+var optimist = require('optimist');
+var prompt = require('prompt');
+var url = require('url');
+var path = require('path');
+var fs = require('fs');
+
+//
+// user home in a os agnostic way
+//
+var tilde =
+ process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'];
+
+var dotf = path.join(tilde, '.ghcopy');
+
+var argv = optimist
+ .usage(
+ 'usage: $0 -u [username]')
+ .alias('u', 'username')
+ .describe('u', 'define the github username')
+ .argv
+ ;
+
+//
+// set the overrides
+//
+prompt.override = argv;
+
+//
+// Start the prompt
+//
+prompt.start();
+
+//
+// Get two properties from the user: username and email
+//
+prompt.get([
+ {name: 'username', required: true},
+ {name: 'password', required: true, hidden: true}], function (err, p) {
+ if(err) {
+ console.log(err.message);
+ process.exit();
+ }
+
+ //
+ // Try to create a api token passing the username and password for
+ // github
+ //
+ var post = {
+ method: "POST",
+ uri: url.format({
+ hostname: 'api.github.com',
+ pathname: "/authorizations",
+ protocol: "https",
+ auth: p.username + ':' + p.password
+ }),
+ json: { "scopes": ["gist"],
+ "note": "Created by http://github.com/dscape/ghcopy",
+ "note_url": "http://github.com/dscape/ghcopy"
+ }
+ };
+
+ //
+ // Request the token from the github api
+ //
+ request(post, function (err, res, body) {
+ if (err) {
+ console.log(err.message);
+ process.exit();
+ }
+
+ //
+ // API code for success is 201
+ //
+ if (res.statusCode !== 201) {
+ console.log("Auth failed, returned status code " + res.statusCode);
+ console.log(body);
+ process.exit();
+ }
+
+ if (typeof body.token !== 'string' || body.token === '') {
+ console.log('Invalid token returned from github');
+ console.log(JSON.stringify(body||{}));
+ process.exit();
+ }
+
+ //
+ // Worked. Yuppy!
+ //
+ var dotfile = JSON.stringify({t: body.token}, null, 2);
+
+ //
+ // Write our dot file
+ //
+ fs.writeFileSync(dotf, dotfile);
+
+ //
+ // chmod if in linux
+ //
+ if(process.platform !== 'win32') {
+ //
+ // r&w, only for user
+ //
+ fs.chmodSync(dotf, '600');
+ }
+
+ //
+ // Show it to our user
+ //
+ console.log(dotfile);
+ });
+
+});
7 license
@@ -0,0 +1,7 @@
+Copyright (c) 2012 Nuno Job
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 package.json
@@ -0,0 +1,32 @@
+{
+ "name": "ghcopy",
+ "version": "0.0.1",
+ "description": "Provides copy to gist functionality for your terminal",
+ "main": "bin/ghcopy.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/dscape/ghcopy.git"
+ },
+ "keywords": [
+ "github",
+ "gist",
+ "copy",
+ "paste",
+ "bin"
+ ],
+ "bin": {
+ "ghcopy": "./bin/ghcopy",
+ "ghcopy-authorize": "./bin/ghcopy-authorize"
+ },
+ "author": "Nuno Job <nunojobpinto@gmail.com> (http://nunojob.com)",
+ "license": "Apache 2",
+ "dependencies": {
+ "optimist": "~0.3.5",
+ "request": "~2.12.0",
+ "prompt": "~0.2.8",
+ "opener": "~1.3.0"
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.