Coder Social home page Coder Social logo

gist's Introduction

gist(1) -- upload code to https://gist.github.com

Synopsis

The gist gem provides a gist command that you can use from your terminal to upload content to https://gist.github.com/.

Installation

‌If you have ruby installed:

gem install gist

‌If you're using Bundler:

source :rubygems
gem 'gist'

‌For OS X, gist lives in Homebrew

brew install gist

‌For FreeBSD, gist lives in ports

pkg install gist

<200c>For Ubuntu/Debian

apt install gist

Note: Debian renames the binary to gist-paste to avoid a name conflict.

Command

‌To upload the contents of a.rb just:

gist a.rb

‌Upload multiple files:

gist a b c
gist *.rb

‌By default it reads from STDIN, and you can set a filename with -f.

gist -f test.rb <a.rb

‌Alternatively, you can just paste from the clipboard:

gist -P

‌Use -p to make the gist private:

gist -p a.rb

‌Use -d to add a description:

gist -d "Random rbx bug" a.rb

‌You can update existing gists with -u:

gist -u GIST_ID FILE_NAME
gist -u 42f2c239d2eb57299408 test.txt

‌If you'd like to copy the resulting URL to your clipboard, use -c.

gist -c <a.rb

‌If you'd like to copy the resulting embeddable URL to your clipboard, use -e.

gist -e <a.rb

‌And you can just ask gist to open a browser window directly with -o.

gist -o <a.rb

‌To list (public gists or all gists for authed user) gists for user

gist -l : all gists for authed user
gist -l defunkt : list defunkt's public gists

To read a gist and print it to STDOUT

gist -r GIST_ID
gist -r 374130

‌See gist --help for more detail.

Login

Before you use gist for the first time you will need to log in. There are two supported login flows:

  1. The Github device-code Oauth flow. This is the default for authenticating to github.com, and can be enabled for Github Enterprise by creating an Oauth app, and exporting the environment variable GIST_CLIENT_ID with the client id of the Oauth app.
  2. The (deprecated) username and password token exchange flow. This is the default for GitHub Enterprise, and can be used to log into github.com by exporting the environment variable GIST_USE_USERNAME_AND_PASSWORD.

The device-code flow

This flow allows you to obtain a token by logging into GitHub in the browser and typing a verification code. This is the preferred mechanism.

gist --login
Requesting login parameters...
Please sign in at https://github.com/login/device
  and enter code: XXXX-XXXX
Success! https://github.com/settings/connections/applications/4f7ec0d4eab38e74384e

The returned access_token is stored in ~/.gist and used for all future gisting. If you need to you can revoke access from https://github.com/settings/connections/applications/4f7ec0d4eab38e74384e.

The username-password flow

This flow asks for your GitHub username and password (and 2FA code), and exchanges them for a token with the "gist" permission (your username and password are not stored). This mechanism is deprecated by GitHub, but may still work with GitHub Enterprise.

gist --login
Obtaining OAuth2 access_token from GitHub.
GitHub username: ConradIrwin
GitHub password:
2-factor auth code:
Success! https://github.com/settings/tokens

This token is stored in ~/.gist and used for all future gisting. If you need to you can revoke it from https://github.com/settings/tokens, or just delete the file.

Password-less login

If you have a complicated authorization requirement you can manually create a token file by pasting a GitHub token with gist scope (and maybe the user:email for GitHub Enterprise) into a file called ~/.gist. You can create one from https://github.com/settings/tokens

This file should contain only the token (~40 hex characters), and to make it easier to edit, can optionally have a final newline (\n or \r\n).

For example, one way to create this file would be to run:

(umask 0077 && echo MY_SECRET_TOKEN > ~/.gist)

The umask ensures that the file is only accessible from your user account.

GitHub Enterprise

If you'd like gist to use your locally installed GitHub Enterprise, you need to export the GITHUB_URL environment variable (usually done in your ~/.bashrc).

export GITHUB_URL=http://github.internal.example.com/

Once you've done this and restarted your terminal (or run source ~/.bashrc), gist will automatically use GitHub Enterprise instead of the public github.com

Your token for GitHub Enterprise will be stored in .gist.<protocol>.<server.name>[.<port>] (e.g. ~/.gist.http.github.internal.example.com for the GITHUB_URL example above) instead of ~/.gist.

If you have multiple servers or use Enterprise and public GitHub often, you can work around this by creating scripts that set the env var and then run gist. Keep in mind that to use the public GitHub you must unset the env var. Just setting it to the public URL will not work. Use unset GITHUB_URL

Token file format

If you cannot use passwords, as most Enterprise installations do, you can generate the token via the web interface and then simply save the string in the correct file. Avoid line breaks or you might see:

$ gist -l
Error: Bad credentials

Library

‌You can also use Gist as a library from inside your ruby code:

Gist.gist("Look.at(:my => 'awesome').code")

If you need more advanced features you can also pass:

  • :access_token to authenticate using OAuth2 (default is `File.read("~/.gist")).
  • :filename to change the syntax highlighting (default is a.rb).
  • :public if you want your gist to have a guessable url.
  • :description to add a description to your gist.
  • :update to update an existing gist (can be a URL or an id).
  • :copy to copy the resulting URL to the clipboard (default is false).
  • :open to open the resulting URL in a browser (default is false).

NOTE: The access_token must have the gist scope and may also require the user:email scope.

‌If you want to upload multiple files in the same gist, you can:

Gist.multi_gist("a.rb" => "Foo.bar", "a.py" => "Foo.bar")

‌If you'd rather use gist's builtin access_token, then you can force the user to obtain one by calling:

Gist.login!

‌This will take them through the process of obtaining an OAuth2 token, and storing it in ~/.gist, where it can later be read by Gist.gist

Configuration

‌If you'd like -o or -c to be the default when you use the gist executable, add an alias to your ~/.bashrc (or equivalent). For example:

alias gist='gist -c'

‌If you'd prefer gist to open a different browser, then you can export the BROWSER environment variable:

export BROWSER=google-chrome

If clipboard or browser integration don't work on your platform, please file a bug or (more ideally) a pull request.

If you need to use an HTTP proxy to access the internet, export the HTTP_PROXY or http_proxy environment variable and gist will use it.

Meta-fu

Thanks to @defunkt and @indirect for writing and maintaining versions 1 through 3. Thanks to @rking and @ConradIrwin for maintaining version 4.

Licensed under the MIT license. Bug-reports, and pull requests are welcome.

gist's People

Contributors

akahn avatar biochimia avatar boucher avatar cliffrowley avatar conradirwin avatar defunkt avatar dlo avatar ermaker avatar flaneur2020 avatar gcbw avatar headius avatar indirect avatar jasonkarns avatar jballin avatar jrk avatar kapadia avatar kui avatar locks avatar lucasrangit avatar mattn avatar metakermit avatar mnvr avatar pix avatar pravj avatar quinnypig avatar rking avatar rmanalan avatar sorah avatar stepheneb avatar zph avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gist's Issues

Creating gist failed: 400 Bad Request

I've updated to 3.0.0 and can't upload gists through the command line.

Both GITHUB_USER and GITHUB_PASSWORD environment variables are set correctly, and I've also updated my .gitconfig with my password (still contains my Github token, too).

zachwill ✩  gist gist.txt 
Creating gist failed: 400 Bad Request

zachwill ✩  gist < gist.txt
Creating gist failed: 400 Bad Request

I'm also using 1.9.3 if that helps:

zachwill ✩  ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]

Add a command-line argument to set the content type

Hey there,

I frequently post diffs to gist. However, when I use your script to post a gist it comes out in raw format. Formatting it correctly is an extra manual step in what is otherwise a brilliantly automated process.

It would be nice if I could run your script using one or more of these syntaxes:

svn diff | gist --type diff
svn diff | gist -t diff
svn diff | gist --type=diff

encoding problems

Running gist on anything—file or stdin—produces this error:

invalid byte sequence in US-ASCII

Adding

#encoding: utf-8

to gist fixes the problem.

I am using the latest gist (2.0.1) and ruby (1.9.2p180).

tag the 2.0.2 release

It would be good if the 2.0.2 release could get tagged in this repository so that the Homebrew formula could be updated.

Thanks!

pbcopy

I'm having trouble with the http://github.com/defunkt/gist/commit/8e80c386206a8e997dcf094bc78ae366b83d9845 commit. It changed:
system("which pbcopy > /dev/null")
to:
system("which pbcopy &> /dev/null")

On my system this produces a error:
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31: command not found: pbcopy

I do not have pbcopy and system("which pbcopy > /dev/null") returns false, whereas system("which pbcopy &> /dev/null") returns true (I believe incorrectly).

undefined method `empty?' for nil:NilClass

Hi, I just install gist from gem, but when ever I try to publish my gist, I got this:

[kissy master]: gist CHANGELOG
undefined method `empty?' for nil:NilClass

[kissy master]: gist -v
1.2.1

All I get is "nil".

Hello,

Can someone of you help me out with Gist? I've installed it through Homebrew, and I have set my username and token inside my ~/.gitconfig file.

However, I'm completely unable to paste anything to the gist command. Is there any way for me to debug this?

Should be some ways for the command to check what is wrong, instead for spit out "nil".

Instructions for setting github.token to a command don't work for me

The README states, "You can also define github.token to be a command which returns the actual token on stdout by setting the variable to a command string prefixed with !." This doesn't work for me and I don't see any mention of it in the git-config man page. The closest mention is in the alias.* section, "If the alias expansion is prefixed with an exclamation point, it will be treated as a shell command." Am I missing something?

On a related note, I think the ability to store the token in the keychain is incredibly useful. The way I'm doing this currently is to set the GITHUB_TOKEN environment variable to the keychain command you have in the README.

export GITHUB_TOKEN=`security 2>&1 >/dev/null find-generic-password -gs github.token | ruby -e 'print $1 if STDIN.gets =~ /^password: "(.*)"$/'`

NOTE The command above differs slightly from the one used in the README in that I've removed the unnecessary backslashes around the double quotes.

I'm happy to issue a pull request with these changes to the README but I wanted to check that my understanding was correct first.

Support for updating gists

It would be nice to be able to push an update to a gist, instead of only creating a new one.

ie, something like this.

$ echo file | gist
https://gist.github.com/$number
$ vim file
$ echo file | gist --update $number

proxy authentication

the username and password in the HTTPS_PROXY environment variable are being ignored, proxy auth fails

I can't create any public gist.

I'm using 3.0.1.

The --no-private option does not work.

README.markdown says that gist.private is yes(private) by default.
So I ran this command.
git config --global gist.private no
But this also did not work.

So I can't create any public gist.

Strip directory from arguments

When I run gist /opt/nginx/conf/nginx.conf it fails with Creating gist failed: 200 OK because it is trying to set the file name to the pull path, instead of just the filename (I assume).

Fails silently on large files

I have a 5.5 MB file I'm trying to gist from the command line. The command exits and no URL or message is displayed. The file isn't posted to gist. I imagine the API is rejecting the file because it's too large. But there's no error message.

Doesn't support ruby1.9

% gist < file.java

/usr/lib/ruby/1.9.1/net/http.rb:1529:in dup': can't dup Symbol (TypeError) from /usr/lib/ruby/1.9.1/net/http.rb:1529:inurlencode'
from /usr/lib/ruby/1.9.1/net/http.rb:1524:in block in encode_kvpair' from /usr/lib/ruby/1.9.1/net/http.rb:1524:inmap'
from /usr/lib/ruby/1.9.1/net/http.rb:1524:in encode_kvpair' from /usr/lib/ruby/1.9.1/net/http.rb:1517:inblock in set_form_data'
from /usr/lib/ruby/1.9.1/net/http.rb:1517:in each' from /usr/lib/ruby/1.9.1/net/http.rb:1517:inmap'
from /usr/lib/ruby/1.9.1/net/http.rb:1517:in set_form_data' from /usr/lib/ruby/1.9.1/net/http.rb:415:inpost_form'
from /usr/bin/gist:33:in write' from /usr/bin/gist:81:in

'

parameter for authentication

Since my ~/.gitconfig is public, I cannot add my GitHub API token to it.

It would be useful to be able to specify the API token via the command line instead.
Alternatively, perhaps there's a way to use the public key from ~/.ssh instead?

"can't dup Symbol"

When trying to upload a file, I get:

% gist run1.count
can't dup Symbol
Usage: gist [options] [filename or stdin] [filename] ...
....

% ruby --version
ruby 1.9.1p243 (2009-07-16 revision 24175) [x86_64-linux]

Enable asynchronous embedding

You can enable the embed code to work asynchronously by prefixing it with eval(document.write.START); and postfixing it with eval(document.write.END);, which does nothing at all, unless ADW is included on a page too, which uses magic (read: Errors) to allow the document.write() calls to be asynchronous.

For example, the following code:

document.write('<link rel="stylesheet" href="http://gist.github.com/stylesheets/gist/embed.css"/>');
document.write('<div id=\"gist-XXXXXX\" class=\"gist\">...gist here...<\/div>');

Would become:

eval(document.write.START);
document.write('<link rel="stylesheet" href="http://gist.github.com/stylesheets/gist/embed.css"/>');
document.write('<div id=\"gist-XXXXXX\" class=\"gist\">...gist here...<\/div>');
eval(document.write.END);

Edit: I seem to have discovered an issue with > escaping in GitHub flavored Markdown by posting this issue. No idea where I'd report that though.

Set gist filename

When I gist a file, it should set the gist filename to the name of the file I'm gisting.

Restore command line access to Gist.read

Versions prior to 2457f44 were able to read from current gists:
$ gist 1234 > something.txt

The ability to both write to and read from gists is extremely useful, thus this functionality should be restored in the current version.

It is a relatively simple task to decipher if a filename, gist ID or uri has been passed as an argument. For example if the filename does not exist, then it can be checked against a regex to see if it is a gist ID or uri. Alternatively a command line option can be specified when the result is ambiguous.

brew install not working (MD5 mismatch)

$ brew install gist
==> Downloading https://github.com/defunkt/gist/tarball/v2.0.0
######################################################################## 100.0%
Error: MD5 mismatch
Expected: 4be2158b5a3d570f0f14d3ba092458db
Got: 509fac5c9d48b5e196b18278291dc46d
Archive: /Users/javan/Library/Caches/Homebrew/gist-2.0.0.0
(To retry an incomplete download, remove the file above.)

Gist fails to verify SSL connection.

When I try to use the tool, I get this error.

SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

I'd prefer not to disable the SSL verification to get this working.
I've used these commands to install gist from an Ubuntu version:

sudo apt-get install ruby
sudo apt-get install rubygems
sudo apt-get install libopenssl-ruby
sudo gem install gist
sudo cp /var/lib/gems/1.8/bin/gist /usr/local/bin/
gist -h

Am I missing something? I've also installed my token and user in the environment variables.

SSL error

SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

won't work for me, no gist created

If I execute the script, no matter which form (stdin or file), just nothing happens.

I found out, that the script is always redirected
the proxy.post_form returns:
#<Net::HTTPFound 302 Found readbody=true>
req.body gives:
"You are being <a href="http://gist.github.com/gists/new\">redirected."

github.user and github.token in my git config are definitely set right.

On ubuntu 9.10 creates the gist, but outputs errors anyway.

gist < database.yml
/usr/bin/gist:86: command not found: pbcopy
Broken pipe
Usage: gist [options] [filename or stdin]
    -p, --private                    Make the gist private
    -t, --type [EXTENSION]           Set syntax highlighting of the Gist by file extension
    -m, --man                        Print manual
    -h, --help                       Display this screen

But the gist is created. Not sure what the errors are about, and it doesn't give me the URL for the gist.

Explicit type given with -t should override file extension

I was trying to add a gist of a shell script which doesn't have a file extension, specifying -t sh and the filename of the script. But the explicit type given is ignored when filenames are given on the commandline, so my gist ends up being typeless.

SSL error "certificate verify failed"

I am getting the following error
$ echo test | gist
SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

Changing the following suppressed the error, although I doubt it is a proper fix.
diff --git a/lib/gist.rb b/lib/gist.rb
index 6ecc10a..be5b119 100644
--- a/lib/gist.rb
+++ b/lib/gist.rb
@@ -119,7 +119,7 @@ module Gist
end

     http.use_ssl = true
-    http.verify_mode = OpenSSL::SSL::VERIFY_PEER
+    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
     http.ca_file = File.join(File.dirname(__FILE__), "cacert.pem")

     req = Net::HTTP::Post.new(url.path)

Also note the following, even though I am currently using commit 1c27da3 (v2.0.0).
$ gist --version
1.4.0
I think somebody forgot to build gist in commit 83bf891. This shouldn't affect the current issue however, as it was just a version bump from v1.4.0.

Possible relevant info:
$ ruby --version
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.