• Stars
    star
    3,792
  • Rank 11,111 (Top 0.3 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 15 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Potentially the best command line gister.

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.

More Repositories

1

jquery-pjax

pushState + ajax = pjax
JavaScript
16,760
star
2

dotjs

~/.js
Ruby
3,160
star
3

facebox

Facebook-style lightbox, built in jQuery
JavaScript
1,926
star
4

unicorn

Unofficial Unicorn Mirror.
Ruby
1,413
star
5

pystache

Mustache in Python
Python
1,307
star
6

github-gem

`github` command line helper for simplifying your GitHub experience.
Ruby
1,122
star
7

cijoe

CI Joe is a fun Continuous Integration server. Unmaintained.
Ruby
1,047
star
8

coffee-mode

Emacs Major Mode for CoffeeScript
Emacs Lisp
574
star
9

gist.el

Yet another Emacs paste mode, this one for Gist.
Emacs Lisp
545
star
10

hurl

Hurl makes HTTP requests.
JavaScript
527
star
11

rip

Take back your $LOAD_PATH. Deprecated and unmaintained.
Ruby
365
star
12

repl

Sometimes you need a REPL. Unmaintained, sorry.
Ruby
360
star
13

textmate.el

Basic emulation of awesome TextMate features for Emacs.
Emacs Lisp
356
star
14

colored

Colors in your terminal. Unmaintained.
Ruby
269
star
15

cache_fu

Ghost from Christmas past. Unmaintained.
Ruby
259
star
16

exception_logger

Unmaintained. Sorry.
Ruby
244
star
17

cheat

Cheating is fun!
Ruby
240
star
18

Zen

Distraction free writing for Atom.
CoffeeScript
194
star
19

emacs

My Emacs config
Emacs Lisp
187
star
20

choice

Choice is a gem for defining and parsing command line options with a friendly DSL.
Ruby
177
star
21

ambition

include Enumerable — Unmaintained
Ruby
166
star
22

markdown-mode

Emacs Markdown mode
Emacs Lisp
155
star
23

lyndon

Lyndon wraps JavaScript in a loving MacRuby embrace. A fun hack that is no longer maintained.
Ruby
144
star
24

nginx_config_generator

Generates nginx config files from YAML.
Ruby
125
star
25

acts_as_textiled

Makes your models act as textiled.
Ruby
115
star
26

resque-lock

A Resque plugin for ensuring only one instance of your job is running at a time.
Ruby
113
star
27

mofo

Mofo was a fast and simple microformat parser, based on a concise DSL and Hpricot. No longer maintained.
JavaScript
90
star
28

gem-man

RubyGems plugin to view a gem's manpage.
Ruby
85
star
29

mustache-sinatra-example

An example of using Mustache in a Sinatra app.
Ruby
79
star
30

quake

The source code to Quake, one of the best games ever.
77
star
31

defunkt.github.com

My GitHub Page
HTML
77
star
32

sake

System wide Rake.
Ruby
76
star
33

starling

Ruby
75
star
34

resque

Moved to resque/resque
57
star
35

ircamp

IRC <-> Campfire Bridge
Python
53
star
36

evilbot

an evil bot that's definitely not for convore
CoffeeScript
50
star
37

jasper

Lispy JavaScript
JavaScript
39
star
38

gibberish

Dead simple Rails localization.
Ruby
37
star
39

Mustache.tmbundle

A little textmate bundle for defunkt/mustache
36
star
40

resque-web

Sinatra-based web UI for Resque
Ruby
30
star
41

ike

Rake in Io.
Io
28
star
42

mapreducerb

Simple map/reduce in Ruby
Ruby
26
star
43

sake-tasks

Your own personal sake tasks, ripe for sharing.
24
star
44

matzbot

matzbot is nice so we are nice
Ruby
22
star
45

mustache-syntax-highlighter

Syntax highlighting plugin for mustache.rb
Ruby
22
star
46

repl-completion

Completion files for repl(1)
22
star
47

sfruby-meetup-resque

My Resque presentation at the SF Ruby Meetup, January 2010
Ruby
21
star
48

zippy

Zippy lil’ zipcode lib.
Ruby
20
star
49

ftpd.rb

A simple ftp daemon, written in Ruby. Do not use — here for historical purposes.
Ruby
19
star
50

subtlety

Subtlety: SVN => RSS, hAtom => Atom
Ruby
17
star
51

cheat.el

Cheat Emacs mode
Emacs Lisp
15
star
52

fixture_scenarios_builder

Build your fixtures in Ruby.
Ruby
15
star
53

resque-cli

A command line program for talking to Resque.
15
star
54

ambitious_activerecord

Unmaintained Ambitious ActiveRecord adapter, for Ambition.
Ruby
14
star
55

ambitious_activeldap

Ambition adapter for ActiveLdap
Ruby
13
star
56

iui

Import of the iui library
JavaScript
13
star
57

dodgeball.github.com

yes
Ruby
12
star
58

ooc-markdown

A Discount binding for ooc
C
11
star
59

sdoc-helpers

Simple helpers to make using sdoc easier.
Ruby
10
star
60

pinder

My fork of Pinder, the Campfire API for Python developers.
Python
9
star
61

metaid

9
star
62

Markdown-problems

Public repository to submit markdown problems to github support
9
star
63

currency_converter

Objective-C
9
star
64

magit

Mirror of the Magit Emacs mode.
Emacs Lisp
8
star
65

burn

Sinatra => Campfire
7
star
66

sakerb

Sake repository served fresh by the guys at Barefoot.
Ruby
7
star
67

barefootexamples

Ruby
7
star
68

repo-in-a-repo

6
star
69

my-awesome-framework

A simple demonstration of how to effectively use Git submodules.
6
star
70

rtimeout

Ruby
6
star
71

redis-namespace

Moved to resque/redis-namespace
6
star
72

ozimodo

An ancient Ruby on Rails powered tumblelog.
6
star
73

electron-wordwrap

6
star
74

my-fun-repo

5
star
75

github-markup

Moved!
5
star
76

lacampfire

Logical Awesome Campfire userscript.
JavaScript
5
star
77

my-fantastic-plugin

A simple demonstration of how to effectively use Git submodules.
4
star