gistl 4.14.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rspec +3 -0
- data/Gemfile +3 -0
- data/LICENSE.MIT +7 -0
- data/README.md +189 -0
- data/Rakefile +44 -0
- data/bin/gist +194 -0
- data/build/gist +1998 -0
- data/build/gist.1 +246 -0
- data/gistl.gemspec +21 -0
- data/lib/gist.rb +566 -0
- data/spec/auth_token_file_spec.rb +61 -0
- data/spec/clipboard_spec.rb +40 -0
- data/spec/ghe_spec.rb +91 -0
- data/spec/gist_spec.rb +23 -0
- data/spec/proxy_spec.rb +21 -0
- data/spec/rawify_spec.rb +12 -0
- data/spec/shorten_spec.rb +11 -0
- data/spec/spec_helper.rb +19 -0
- data/vendor/json.rb +1304 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 38cf24bf54a3014a62630d87d34e929159eacdd5
|
4
|
+
data.tar.gz: 576ca7e1009a40d2df28735b814b14d07ffe932b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1b0c7e8ab1e0afef5f3aae4935150c2fe2a2da2522505557b5b315e92052b825f90d537c862b0d11f662853e7ccea74ae353b5ad7a027e3646810d0599b900b7
|
7
|
+
data.tar.gz: 8688d8bbea4a56e36e39db84609fc0a8769dd2ad0bd64999c6c92bc71d9a0164413a121f200f23a7b7f4089e17017df1ed2cbfd08d977357128fda44aefd4c92
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.MIT
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2012 Conrad Irwin <conrad.irwin@gmail.com>
|
2
|
+
|
3
|
+
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:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
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.
|
data/README.md
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
gist(1) -- upload code to https://gist.github.com
|
2
|
+
=================================================
|
3
|
+
|
4
|
+
## Synopsis
|
5
|
+
|
6
|
+
The gist gem provides a `gist` command that you can use from your terminal to
|
7
|
+
upload content to https://gist.github.com/.
|
8
|
+
|
9
|
+
## Fork-specific info
|
10
|
+
|
11
|
+
[![Latest Version](https://img.shields.io/gem/v/gistl.svg)](https://rubygems.org/gems/gistl)
|
12
|
+
|
13
|
+
This fork enhances [defunkt/gist](https://github.com/defunkt/gist) in the
|
14
|
+
following ways:
|
15
|
+
|
16
|
+
* Enhanced listing: additional options `--days`, `--number`, `--pages` for
|
17
|
+
faster and more fine-grained listing;
|
18
|
+
* Civilized citizen: token is saved to `$XDG_DATA_HOME/gist/token` instead of
|
19
|
+
`$HOME/.gist`.
|
20
|
+
|
21
|
+
This fork is published to RubyGems.org as
|
22
|
+
[`gistl`](https://rubygems.org/gems/gistl).
|
23
|
+
|
24
|
+
To distinguish ourselves from the upstream, the version number is always ahead
|
25
|
+
of the upstream by 0.10.0.
|
26
|
+
|
27
|
+
## Installation
|
28
|
+
|
29
|
+
If you have ruby installed:
|
30
|
+
|
31
|
+
gem install gist
|
32
|
+
|
33
|
+
If you're using Bundler:
|
34
|
+
|
35
|
+
source :rubygems
|
36
|
+
gem 'gist'
|
37
|
+
|
38
|
+
For OS X, gist lives in Homebrew
|
39
|
+
|
40
|
+
brew install gist
|
41
|
+
|
42
|
+
## Command
|
43
|
+
|
44
|
+
To upload the contents of `a.rb` just:
|
45
|
+
|
46
|
+
gist a.rb
|
47
|
+
|
48
|
+
Upload multiple files:
|
49
|
+
|
50
|
+
gist a b c
|
51
|
+
gist *.rb
|
52
|
+
|
53
|
+
By default it reads from STDIN, and you can set a filename with `-f`.
|
54
|
+
|
55
|
+
gist -f test.rb <a.rb
|
56
|
+
|
57
|
+
Alternatively, you can just paste from the clipboard:
|
58
|
+
|
59
|
+
gist -P
|
60
|
+
|
61
|
+
Use `-p` to make the gist private:
|
62
|
+
|
63
|
+
gist -p a.rb
|
64
|
+
|
65
|
+
Use `-d` to add a description:
|
66
|
+
|
67
|
+
gist -d "Random rbx bug" a.rb
|
68
|
+
|
69
|
+
You can update existing gists with `-u`:
|
70
|
+
|
71
|
+
gist -u GIST_ID FILE_NAME
|
72
|
+
gist -u 42f2c239d2eb57299408 test.txt
|
73
|
+
|
74
|
+
If you'd like to copy the resulting URL to your clipboard, use `-c`.
|
75
|
+
|
76
|
+
gist -c <a.rb
|
77
|
+
|
78
|
+
If you'd like to copy the resulting embeddable URL to your clipboard, use `-e`.
|
79
|
+
|
80
|
+
gist -e <a.rb
|
81
|
+
|
82
|
+
And you can just ask gist to open a browser window directly with `-o`.
|
83
|
+
|
84
|
+
gist -o <a.rb
|
85
|
+
|
86
|
+
To list (public gists or all gists for authed user) gists for user
|
87
|
+
|
88
|
+
gist -l : all gists for authed user
|
89
|
+
gist -l defunkt : list defunkt's public gists
|
90
|
+
|
91
|
+
See `gist --help` for more detail.
|
92
|
+
|
93
|
+
## Login
|
94
|
+
|
95
|
+
If you want to associate your gists with your GitHub account, you need to login
|
96
|
+
with gist. It doesn't store your username and password, it just uses them to get
|
97
|
+
an OAuth2 token (with the "gist" permission).
|
98
|
+
|
99
|
+
gist --login
|
100
|
+
Obtaining OAuth2 access_token from github.
|
101
|
+
GitHub username: ConradIrwin
|
102
|
+
GitHub password:
|
103
|
+
2-factor auth code:
|
104
|
+
Success! https://github.com/settings/applications
|
105
|
+
|
106
|
+
You can read the 2-factor auth code from an sms or the authentication app,
|
107
|
+
depending on how you [set your account up](https://github.com/settings/admin).
|
108
|
+
|
109
|
+
Note: 2-factor authentication
|
110
|
+
[just appeared recently](https://github.com/blog/1614-two-factor-authentication),
|
111
|
+
so if you run into errors, update the gist gem.
|
112
|
+
|
113
|
+
gem update gist
|
114
|
+
|
115
|
+
This token is stored in `~/.gist` and used for all future gisting. If you need to
|
116
|
+
you can revoke it from https://github.com/settings/applications, or just delete the
|
117
|
+
file. If you need to store tokens for both github.com and a Github Enterprise instance
|
118
|
+
you can save your Github Enterprise token in `~/.gist.github.example.com` where
|
119
|
+
"github.example.com" is the URL for your Github Enterprise instance.
|
120
|
+
|
121
|
+
After you've done this, you can still upload gists anonymously with `-a`.
|
122
|
+
|
123
|
+
gist -a a.rb
|
124
|
+
|
125
|
+
# Library
|
126
|
+
|
127
|
+
You can also use Gist as a library from inside your ruby code:
|
128
|
+
|
129
|
+
Gist.gist("Look.at(:my => 'awesome').code")
|
130
|
+
|
131
|
+
If you need more advanced features you can also pass:
|
132
|
+
|
133
|
+
* `:access_token` to authenticate using OAuth2 (default is `File.read("~/.gist")).
|
134
|
+
* `:filename` to change the syntax highlighting (default is `a.rb`).
|
135
|
+
* `:public` if you want your gist to have a guessable url.
|
136
|
+
* `:description` to add a description to your gist.
|
137
|
+
* `:update` to update an existing gist (can be a URL or an id).
|
138
|
+
* `:anonymous` to submit an anonymous gist (default is false).
|
139
|
+
* `:copy` to copy the resulting URL to the clipboard (default is false).
|
140
|
+
* `:open` to open the resulting URL in a browser (default is false).
|
141
|
+
|
142
|
+
NOTE: The access_token must have the "gist" scope.
|
143
|
+
|
144
|
+
If you want to upload multiple files in the same gist, you can:
|
145
|
+
|
146
|
+
Gist.multi_gist("a.rb" => "Foo.bar", "a.py" => "Foo.bar")
|
147
|
+
|
148
|
+
If you'd rather use gist's builtin access_token, then you can force the user
|
149
|
+
to obtain one by calling:
|
150
|
+
|
151
|
+
Gist.login!
|
152
|
+
|
153
|
+
This will take them through the process of obtaining an OAuth2 token, and storing it
|
154
|
+
in `~/.gist`, where it can later be read by `Gist.gist`
|
155
|
+
|
156
|
+
## GitHub enterprise
|
157
|
+
|
158
|
+
If you'd like `gist` to use your locally installed [GitHub Enterprise](https://enterprise.github.com/),
|
159
|
+
you need to export the `GITHUB_URL` environment variable in your `~/.bashrc`.
|
160
|
+
|
161
|
+
export GITHUB_URL=http://github.internal.example.com/
|
162
|
+
|
163
|
+
Once you've done this and restarted your terminal (or run `source ~/.bashrc`), gist will
|
164
|
+
automatically use github enterprise instead of the public github.com
|
165
|
+
|
166
|
+
## Configuration
|
167
|
+
|
168
|
+
If you'd like `-o` or `-c` to be the default when you use the gist executable, add an
|
169
|
+
alias to your `~/.bashrc` (or equivalent). For example:
|
170
|
+
|
171
|
+
alias gist='gist -c'
|
172
|
+
|
173
|
+
If you'd prefer gist to open a different browser, then you can export the BROWSER
|
174
|
+
environment variable:
|
175
|
+
|
176
|
+
export BROWSER=google-chrome
|
177
|
+
|
178
|
+
If clipboard or browser integration don't work on your platform, please file a bug or
|
179
|
+
(more ideally) a pull request.
|
180
|
+
|
181
|
+
If you need to use an HTTP proxy to access the internet, export the `HTTP_PROXY` or
|
182
|
+
`http_proxy` environment variable and gist will use it.
|
183
|
+
|
184
|
+
## Meta-fu
|
185
|
+
|
186
|
+
Thanks to @defunkt and @indirect for writing and maintaining versions 1 through 3.
|
187
|
+
Thanks to @rking and @ConradIrwin for maintaining version 4.
|
188
|
+
|
189
|
+
Licensed under the MIT license. Bug-reports, and pull requests are welcome.
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
task :default => :test
|
2
|
+
|
3
|
+
desc 'run the tests' # that's non-DRY
|
4
|
+
task :test do
|
5
|
+
sh 'rspec spec'
|
6
|
+
end
|
7
|
+
|
8
|
+
task :clipfailtest do
|
9
|
+
sh 'PATH=/ /usr/bin/ruby -Ilib -S bin/gist -ac < lib/gist.rb'
|
10
|
+
end
|
11
|
+
|
12
|
+
task :man do
|
13
|
+
mkdir_p "build"
|
14
|
+
File.write "README.md.ron", File.read("README.md").gsub("\u200c", "* ")
|
15
|
+
sh 'ronn --roff --manual="Gist manual" README.md.ron'
|
16
|
+
rm 'README.md.ron'
|
17
|
+
mv 'README.1', 'build/gist.1'
|
18
|
+
end
|
19
|
+
|
20
|
+
task :standalone do
|
21
|
+
mkdir_p "build"
|
22
|
+
File.open("build/gist", "w") do |f|
|
23
|
+
f.puts "#!/usr/bin/env ruby"
|
24
|
+
f.puts "# This is generated from https://github.com/defunkt/gist using 'rake standalone'"
|
25
|
+
f.puts "# any changes will be overwritten."
|
26
|
+
f.puts File.read("lib/gist.rb").split("require 'json'\n").join(File.read("vendor/json.rb"))
|
27
|
+
|
28
|
+
f.puts File.read("bin/gist").gsub(/^require.*gist.*\n/, '');
|
29
|
+
end
|
30
|
+
sh 'chmod +x build/gist'
|
31
|
+
end
|
32
|
+
|
33
|
+
task :build => [:man, :standalone]
|
34
|
+
|
35
|
+
desc "Install standalone script and man pages"
|
36
|
+
task :install => :standalone do
|
37
|
+
prefix = ENV['PREFIX'] || ENV['prefix'] || '/usr/local'
|
38
|
+
|
39
|
+
FileUtils.mkdir_p "#{prefix}/bin"
|
40
|
+
FileUtils.cp "build/gist", "#{prefix}/bin"
|
41
|
+
|
42
|
+
FileUtils.mkdir_p "#{prefix}/share/man/man1"
|
43
|
+
FileUtils.cp "build/gist.1", "#{prefix}/share/man/man1"
|
44
|
+
end
|
data/bin/gist
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Silence Ctrl-C's
|
4
|
+
trap('INT'){ exit 1 }
|
5
|
+
trap('PIPE', 'EXIT')
|
6
|
+
|
7
|
+
require 'date'
|
8
|
+
require 'optparse'
|
9
|
+
require 'gist'
|
10
|
+
|
11
|
+
# For the holdings of options.
|
12
|
+
options = {}
|
13
|
+
filenames = []
|
14
|
+
|
15
|
+
OptionParser.new do |opts|
|
16
|
+
executable_name = File.split($0)[1]
|
17
|
+
opts.banner = <<-EOS
|
18
|
+
Gist (v#{Gist::VERSION}) lets you upload to https://gist.github.com/
|
19
|
+
|
20
|
+
The content to be uploaded can be passed as a list of files, if none are
|
21
|
+
specified STDIN will be read. The default filename for STDIN is "a.rb", and all
|
22
|
+
filenames can be overridden by repeating the "-f" flag. The most useful reason
|
23
|
+
to do this is to change the syntax highlighting.
|
24
|
+
|
25
|
+
If you'd like your gists to be associated with your GitHub account, so that you
|
26
|
+
can edit them and find them in future, first use `gist --login` to obtain an
|
27
|
+
Oauth2 access token. This is stored and used by gist in the future.
|
28
|
+
|
29
|
+
Private gists do not have guessable URLs and can be created with "-p", you can
|
30
|
+
also set the description at the top of the gist by passing "-d".
|
31
|
+
|
32
|
+
Anonymous gists are not associated with your GitHub account, they can be created
|
33
|
+
with "-a" even after you have used "gist --login".
|
34
|
+
|
35
|
+
If you would like to shorten the resulting gist URL, use the -s flag. This will
|
36
|
+
use GitHub's URL shortener, git.io. You can also use -R to get the link to the
|
37
|
+
raw gist.
|
38
|
+
|
39
|
+
To copy the resulting URL to your clipboard you can use the -c option, or to
|
40
|
+
just open it directly in your browser, use -o. Using the -e option will copy the
|
41
|
+
embeddable URL to the clipboard. You can add `alias gist='gist -c'` to your
|
42
|
+
shell's rc file to configure this behaviour by default.
|
43
|
+
|
44
|
+
Instead of creating a new gist, you can update an existing one by passing its ID
|
45
|
+
or URL with "-u". For this to work, you must be logged in, and have created the
|
46
|
+
original gist with the same GitHub account.
|
47
|
+
|
48
|
+
Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P] [-f NAME|-t EXT]* FILE*
|
49
|
+
#{executable_name} --login
|
50
|
+
|
51
|
+
EOS
|
52
|
+
|
53
|
+
opts.on("--login", "Authenticate gist on this computer.") do
|
54
|
+
Gist.login!
|
55
|
+
exit
|
56
|
+
end
|
57
|
+
|
58
|
+
opts.on("-f", "--filename [NAME.EXTENSION]", "Sets the filename and syntax type.") do |filename|
|
59
|
+
filenames << filename
|
60
|
+
options[:filename] = filename
|
61
|
+
end
|
62
|
+
|
63
|
+
opts.on("-t", "--type [EXTENSION]", "Sets the file extension and syntax type.") do |extension|
|
64
|
+
filenames << "foo.#{extension}"
|
65
|
+
options[:filename] = "foo.#{extension}"
|
66
|
+
end
|
67
|
+
|
68
|
+
opts.on("-p", "--private", "Makes your gist private.") do
|
69
|
+
options[:private] = true
|
70
|
+
end
|
71
|
+
|
72
|
+
opts.on("--no-private") do
|
73
|
+
options[:private] = false
|
74
|
+
end
|
75
|
+
|
76
|
+
opts.on("-d", "--description DESCRIPTION", "Adds a description to your gist.") do |description|
|
77
|
+
options[:description] = description
|
78
|
+
end
|
79
|
+
|
80
|
+
opts.on("-s", "--shorten", "Shorten the gist URL using git.io.") do |shorten|
|
81
|
+
options[:shorten] = shorten
|
82
|
+
end
|
83
|
+
|
84
|
+
opts.on("-u", "--update [ URL | ID ]", "Update an existing gist.") do |update|
|
85
|
+
options[:update] = update
|
86
|
+
end
|
87
|
+
|
88
|
+
opts.on("-a", "--anonymous", "Create an anonymous gist.") do
|
89
|
+
options[:anonymous] = true
|
90
|
+
end
|
91
|
+
|
92
|
+
opts.on("-c", "--copy", "Copy the resulting URL to the clipboard") do
|
93
|
+
options[:copy] = true
|
94
|
+
end
|
95
|
+
|
96
|
+
opts.on("-e", "--embed", "Copy the embed code for the gist to the clipboard") do
|
97
|
+
options[:embed] = true
|
98
|
+
options[:copy] = true
|
99
|
+
end
|
100
|
+
|
101
|
+
opts.on("-o", "--open", "Open the resulting URL in a browser") do
|
102
|
+
options[:open] = true
|
103
|
+
end
|
104
|
+
|
105
|
+
opts.on("--no-open")
|
106
|
+
|
107
|
+
opts.on("-P", "--paste", "Paste from the clipboard to gist") do
|
108
|
+
options[:paste] = true
|
109
|
+
end
|
110
|
+
|
111
|
+
opts.on("-R", "--raw", "Display raw URL of the new gist") do
|
112
|
+
options[:raw] = true
|
113
|
+
end
|
114
|
+
|
115
|
+
opts.on("-l", "--list [USER]", "List gists for user (all by default)") do |user|
|
116
|
+
options[:list] = user
|
117
|
+
end
|
118
|
+
|
119
|
+
opts.on("--days [NUMBER]", OptionParser::DecimalInteger,
|
120
|
+
"Only list gists updated in the past NUMBER days (in conjuction with --list)") do |number|
|
121
|
+
options[:since] = DateTime.now - number
|
122
|
+
end
|
123
|
+
|
124
|
+
opts.on("--number [NUMBER]", OptionParser::DecimalInteger,
|
125
|
+
"Maximum number of gists (in conjuction with --list)") do |number|
|
126
|
+
options[:max_number] = number
|
127
|
+
end
|
128
|
+
|
129
|
+
opts.on("--pages [NUMBER]", OptionParser::DecimalInteger,
|
130
|
+
"Maximum number of pages (in conjuction with --list)") do |pages|
|
131
|
+
options[:max_pages] = pages
|
132
|
+
end
|
133
|
+
|
134
|
+
opts.on_tail("-h","--help", "Show this message.") do
|
135
|
+
puts opts
|
136
|
+
exit
|
137
|
+
end
|
138
|
+
|
139
|
+
opts.on_tail("-v", "--version", "Print the version.") do
|
140
|
+
puts "gist v#{Gist::VERSION}"
|
141
|
+
exit
|
142
|
+
end
|
143
|
+
|
144
|
+
end.parse!
|
145
|
+
|
146
|
+
begin
|
147
|
+
options[:output] = if options[:embed] && options[:shorten]
|
148
|
+
raise Gist::Error, "--embed does not make sense with --shorten"
|
149
|
+
elsif options[:embed]
|
150
|
+
:javascript
|
151
|
+
elsif options[:shorten] and options[:raw]
|
152
|
+
:short_raw_url
|
153
|
+
elsif options[:shorten]
|
154
|
+
:short_url
|
155
|
+
elsif options[:raw]
|
156
|
+
:raw_url
|
157
|
+
else
|
158
|
+
:html_url
|
159
|
+
end
|
160
|
+
|
161
|
+
options[:public] = Gist.should_be_public?(options)
|
162
|
+
|
163
|
+
if options.key? :list
|
164
|
+
user = options[:list] ? options[:list] : ""
|
165
|
+
Gist.list_all_gists(user, options)
|
166
|
+
exit
|
167
|
+
end
|
168
|
+
|
169
|
+
if options[:paste]
|
170
|
+
puts Gist.gist(Gist.paste, options)
|
171
|
+
else
|
172
|
+
to_read = ARGV.empty? ? ['-'] : ARGV
|
173
|
+
files = {}
|
174
|
+
to_read.zip(filenames).each do |(file, name)|
|
175
|
+
files[name || file] =
|
176
|
+
begin
|
177
|
+
if file == '-'
|
178
|
+
$stderr.puts "(type a gist. <ctrl-c> to cancel, <ctrl-d> when done)" if $stdin.tty?
|
179
|
+
STDIN.read
|
180
|
+
else
|
181
|
+
File.read(File.expand_path(file))
|
182
|
+
end
|
183
|
+
rescue => e
|
184
|
+
raise e.extend(Gist::Error)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
puts Gist.multi_gist(files, options)
|
189
|
+
end
|
190
|
+
|
191
|
+
rescue Gist::Error => e
|
192
|
+
puts "Error: #{e.message}"
|
193
|
+
exit 1
|
194
|
+
end
|