gist 3.0.2 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ .rvmrc
2
+ Gemfile.lock
3
+
4
+ # OS X
5
+ .DS_Store
6
+ .yardoc
7
+ doc
8
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format progress
3
+ -r ./spec/spec_helper.rb
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
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,149 @@
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
+ ## Installation
10
+
11
+ ‌If you have ruby installed:
12
+
13
+ gem install gist
14
+
15
+ ‌If you're using Bundler:
16
+
17
+ source :rubygems
18
+ gem 'gist'
19
+
20
+ ## Command
21
+
22
+ ‌To upload the contents of `a.rb` just:
23
+
24
+ gist a.rb
25
+
26
+ ‌Upload multiple files:
27
+
28
+ gist a b c
29
+ gist *.rb
30
+
31
+ ‌By default it reads from STDIN, and you can set a filename with `-f`.
32
+
33
+ gist -f test.rb <a.rb
34
+
35
+ ‌Alternatively, you can just paste from the clipboard:
36
+
37
+ gist -P
38
+
39
+ ‌Use `-p` to make the gist private:
40
+
41
+ gist -p a.rb
42
+
43
+ ‌Use `-d` to add a description:
44
+
45
+ gist -d "Random rbx bug" a.rb
46
+
47
+ ‌You can update existing gists with `-u`:
48
+
49
+ gist lib/gist.rb bin/gist -u 42f2c239d2eb57299408
50
+
51
+ ‌If you'd like to copy the resulting URL to your clipboard, use `-c`.
52
+
53
+ gist -c <a.rb
54
+
55
+ ‌If you'd like to copy the resulting embeddable URL to your clipboard, use `--copy-js`.
56
+
57
+ gist --copy-js <a.rb
58
+
59
+ ‌And you can just ask gist to open a browser window directly with `-o`.
60
+
61
+ gist -o <a.rb
62
+
63
+ ‌See `gist --help` for more detail.
64
+
65
+ ## Login
66
+
67
+ If you want to associate your gists with your GitHub account, you need to login
68
+ with gist. It doesn't store your username and password, it just uses them to get
69
+ an OAuth2 token (with the "gist" permission).
70
+
71
+ gist --login
72
+ Obtaining OAuth2 access_token from github.
73
+ GitHub username: ConradIrwin
74
+ GitHub password:
75
+ Success! https://github.com/settings/applications
76
+
77
+ This token is stored in `~/.gist` and used for all future gisting. If you need to
78
+ you can revoke it from https://github.com/settings/applications, or just delete the
79
+ file.
80
+
81
+ ‌After you've done this, you can still upload gists anonymously with `-a`.
82
+
83
+ gist -a a.rb
84
+
85
+ # Library
86
+
87
+ ‌You can also use Gist as a library from inside your ruby code:
88
+
89
+ Gist.gist("Look.at(:my => 'awesome').code")
90
+
91
+ If you need more advanced features you can also pass:
92
+
93
+ * `:access_token` to authenticate using OAuth2 (default is `File.read("~/.gist")).
94
+ * `:filename` to change the syntax highlighting (default is `a.rb`).
95
+ * `:public` if you want your gist to have a guessable url.
96
+ * `:description` to add a description to your gist.
97
+ * `:update` to update an existing gist (can be a URL or an id).
98
+ * `:anonymous` to submit an anonymous gist (default is false).
99
+ * `:copy` to copy the resulting URL to the clipboard (default is false).
100
+ * `:open` to open the resulting URL in a browser (default is false).
101
+
102
+ NOTE: The access_token must have the "gist" scope.
103
+
104
+ ‌If you want to upload multiple files in the same gist, you can:
105
+
106
+ Gist.multi_gist("a.rb" => "Foo.bar", "a.py" => "Foo.bar")
107
+
108
+ ‌If you'd rather use gist's builtin access_token, then you can force the user
109
+ to obtain one by calling:
110
+
111
+ Gist.login!
112
+
113
+ ‌This will take them through the process of obtaining an OAuth2 token, and storing it
114
+ in `~/.gist`, where it can later be read by `Gist.gist`
115
+
116
+ ## GitHub enterprise
117
+
118
+ ‌If you'd like `gist` to use your locally installed [GitHub Enterprise](https://enterprise.github.com/),
119
+ you need to export the `GITHUB_URL` environment variable in your `~/.bashrc`.
120
+
121
+ export GITHUB_URL=http://github.internal.example.com/
122
+
123
+ ‌Once you've done this and restarted your terminal (or run `source ~/.bashrc`), gist will
124
+ automatically use github enterprise instead of the public github.com
125
+
126
+ ## Configuration
127
+
128
+ ‌If you'd like `-o` or `-c` to be the default when you use the gist executable, add an
129
+ alias to your `~/.bashrc` (or equivalent). For example:
130
+
131
+ alias gist='gist -c'
132
+
133
+ ‌If you'd prefer gist to open a different browser, then you can export the BROWSER
134
+ environment variable:
135
+
136
+ export BROWSER=google-chrome
137
+
138
+ If clipboard or browser integration don't work on your platform, please file a bug or
139
+ (more ideally) a pull request.
140
+
141
+ If you need to use an HTTP proxy to access the internet, export the `HTTP_PROXY` or
142
+ `http_proxy` environment variable and gist will use it.
143
+
144
+ ## Meta-fu
145
+
146
+ Thanks to @defunkt and @indirect for writing and maintaining versions 1 through 3.
147
+ Thanks to @rking and @ConradIrwin for maintaining version 4.
148
+
149
+ Licensed under the MIT license. Bug-reports, and pull requests are welcome.
data/Rakefile CHANGED
@@ -1,51 +1,19 @@
1
- begin
2
- require "mg"
3
- MG.new("gist.gemspec")
4
- rescue LoadError
5
- nil
6
- end
7
-
8
- desc "Build standalone script and manpages"
9
- task :build => [ :standalone, :build_man ]
10
-
11
- desc "Build standalone script"
12
- task :standalone => :load_gist do
13
- require 'gist/standalone'
14
- Gist::Standalone.save('gist')
15
- end
16
-
17
- desc "Build gist manual"
18
- task :build_man do
19
- sh "ronn -br5 --organization=GITHUB --manual='Gist Manual' man/*.ron"
20
- end
1
+ # encoding: utf-8
2
+ #
3
+ task :default => :test
21
4
 
22
- desc "Show gist manual"
23
- task :man => :build_man do
24
- exec "man man/gist.1"
5
+ desc 'run the tests' # that's non-DRY
6
+ task :test do
7
+ sh 'rspec spec'
25
8
  end
26
9
 
27
- task :load_gist do
28
- $LOAD_PATH.unshift 'lib'
29
- require 'gist'
10
+ task :clipfailtest do
11
+ sh 'PATH=/ /usr/bin/ruby -Ilib -S bin/gist -ac < lib/gist.rb'
30
12
  end
31
13
 
32
- Rake::TaskManager.class_eval do
33
- def remove_task(task_name)
34
- @tasks.delete(task_name.to_s)
35
- end
14
+ task :man do
15
+ File.write "README.md.ron", File.read("README.md").gsub(?‌, "* ")
16
+ sh 'ronn --roff --manual="Gist manual" README.md.ron'
17
+ rm 'README.md.ron'
18
+ sh 'man ./README.1'
36
19
  end
37
-
38
- # Remove mg's install task
39
- Rake.application.remove_task(:install)
40
-
41
- desc "Install standalone script and man pages"
42
- task :install => :standalone do
43
- prefix = ENV['PREFIX'] || ENV['prefix'] || '/usr/local'
44
-
45
- FileUtils.mkdir_p "#{prefix}/bin"
46
- FileUtils.cp "gist", "#{prefix}/bin"
47
-
48
- FileUtils.mkdir_p "#{prefix}/share/man/man1"
49
- FileUtils.cp "man/gist.1", "#{prefix}/share/man/man1"
50
- end
51
-
data/bin/gist CHANGED
@@ -1,20 +1,157 @@
1
1
  #!/usr/bin/env ruby
2
- #
3
- # = gist(1)
4
- #
5
- # == USAGE
6
- # gist < file.txt
7
- # echo secret | gist -p # or --private
8
- # echo "puts :hi" | gist -t rb
9
- # gist script.py
10
- #
11
- # == INSTALL
12
- # RubyGem:
13
- # gem install gist
14
- # Old school:
15
- # curl -s http://github.com/defunkt/gist/raw/master/gist > gist &&
16
- # chmod 755 gist &&
17
- # mv gist /usr/local/bin/gist
18
-
19
- require 'gist'
20
- Gist.execute(*ARGV)
2
+
3
+ require 'optparse'
4
+ require File.expand_path('../../lib/gist', __FILE__)
5
+
6
+ # For the holdings of options.
7
+ options = {}
8
+ filenames = []
9
+
10
+ opts = OptionParser.new do |opts|
11
+ executable_name = File.split($0)[1]
12
+ opts.banner = <<-EOS
13
+ Gist (v#{Gist::VERSION}) lets you upload to https://gist.github.com/
14
+
15
+ The content to be uploaded can be passed as a list of files, if none are
16
+ specified STDIN will be read. The default filename for STDIN is "a.rb", and all
17
+ filenames can be overridden by repeating the "-f" flag. The most useful reason
18
+ to do this is to change the syntax highlighting.
19
+
20
+ If you'd like your gists to be associated with your GitHub account, so that you
21
+ can edit them and find them in future, first use `gist --login` to obtain an
22
+ Oauth2 access token. This is stored and used by gist in the future.
23
+
24
+ Private gists do not have guessable URLs and can be created with "-p", you can
25
+ also set the description at the top of the gist by passing "-d".
26
+
27
+ Anonymous gists are not associated with your GitHub account, they can be created
28
+ with "-a" even after you have used "gist --login".
29
+
30
+ If you would like to shorten the resulting gist URL, use the -s flag. This will
31
+ use GitHub's URL shortener, git.io.
32
+
33
+ To copy the resulting URL to your clipboard you can use the -c option, or to
34
+ just open it directly in your browser, use -o. Using the -e option will copy the
35
+ embeddable URL to the clipboard. You can add `alias gist='gist -c'` to your
36
+ shell's rc file to configure this behaviour by default.
37
+
38
+ Instead of creating a new gist, you can update an existing one by passing its ID
39
+ or URL with "-u". For this to work, you must be logged in, and have created the
40
+ original gist with the same GitHub account.
41
+
42
+ Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-d DESC] -a] [-u URL] [-P] [-f NAME|-t EXT]* FILE*
43
+ #{executable_name} --login
44
+
45
+ EOS
46
+
47
+ opts.on("--login", "Authenticate gist on this computer.") do
48
+ Gist.login!
49
+ exit
50
+ end
51
+
52
+ opts.on("-f", "--filename [NAME.EXTENSION]", "Sets the filename and syntax type.") do |filename|
53
+ filenames << filename
54
+ options[:filename] = filename
55
+ end
56
+
57
+ opts.on("-t", "--type [EXTENSION]", "Sets the file extension and syntax type.") do |extension|
58
+ filenames << "foo.#{extension}"
59
+ options[:filename] = "foo.#{extension}"
60
+ end
61
+
62
+ opts.on("-p", "--private", "Makes your gist private.") do
63
+ options[:private] = true
64
+ end
65
+
66
+ opts.on("--no-private") do
67
+ options[:private] = false
68
+ end
69
+
70
+ opts.on("-d", "--description DESCRIPTION", "Adds a description to your gist.") do |description|
71
+ options[:description] = description
72
+ end
73
+
74
+ opts.on("-s", "--shorten", "Shorten the gist URL using git.io.") do |shorten|
75
+ options[:shorten] = shorten
76
+ end
77
+
78
+ opts.on("-u", "--update [ URL | ID ]", "Update an existing gist.") do |update|
79
+ options[:update] = update
80
+ end
81
+
82
+ opts.on("-a", "--anonymous", "Create an anonymous gist.") do
83
+ options[:anonymous] = true
84
+ end
85
+
86
+ opts.on("-c", "--copy", "Copy the resulting URL to the clipboard") do
87
+ options[:copy] = true
88
+ end
89
+
90
+ opts.on("-e", "--embed", "Copy the embed code for the gist to the clipboard") do
91
+ options[:embed] = true
92
+ options[:copy] = true
93
+ end
94
+
95
+ opts.on("-o", "--open", "Open the resulting URL in a browser") do
96
+ options[:open] = true
97
+ end
98
+
99
+ opts.on("--no-open")
100
+
101
+ opts.on("-P", "--paste", "Paste from the clipboard to gist") do
102
+ options[:paste] = true
103
+ end
104
+
105
+ opts.on_tail("-h","--help", "Show this message.") do
106
+ puts opts
107
+ exit
108
+ end
109
+
110
+ opts.on_tail("-v", "--version", "Print the version.") do
111
+ puts "gist v#{Gist::VERSION}"
112
+ exit
113
+ end
114
+
115
+ end
116
+ opts.parse!
117
+
118
+ begin
119
+ options[:output] = if options[:embed] && options[:shorten]
120
+ raise Gist::Error, "--embed does not make sense with --shorten"
121
+ elsif options[:embed]
122
+ :javascript
123
+ elsif options[:shorten]
124
+ :short_url
125
+ else
126
+ :html_url
127
+ end
128
+
129
+ options[:public] = Gist.should_be_public?(options)
130
+
131
+ if options[:paste]
132
+ puts Gist.gist(Gist.paste, options)
133
+ else
134
+ to_read = ARGV.empty? ? ['-'] : ARGV
135
+ files = {}
136
+ to_read.zip(filenames).each do |(file, name)|
137
+ files[name || file] =
138
+ begin
139
+ if file == '-'
140
+ $stderr.puts "(type a gist. <ctrl-c> to cancel, <ctrl-d> when done)" if $stdin.tty?
141
+ STDIN.read
142
+ else
143
+ File.read(File.expand_path(file))
144
+ end
145
+ rescue => e
146
+ raise e.extend(Gist::Error)
147
+ end
148
+ end
149
+
150
+ puts Gist.multi_gist(files, options)
151
+ end
152
+ rescue Gist::Error => e
153
+ puts "Error: #{e.message}"
154
+ exit 1
155
+ rescue Interrupt
156
+ # bye!
157
+ end
data/gist.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ require './lib/gist'
3
+ Gem::Specification.new do |s|
4
+ s.name = 'gist'
5
+ s.version = Gist::VERSION
6
+ s.summary = 'Just allows you to upload gists'
7
+ s.description = 'Provides a single function (Gist.gist) that uploads a gist.'
8
+ s.homepage = 'https://github.com/defunkt/gist'
9
+ s.email = ['conrad.irwin@gmail.com', 'rkingist@sharpsaw.org']
10
+ s.authors = ['Conrad Irwin', '☈king']
11
+ s.license = 'MIT'
12
+ s.files = `git ls-files`.split("\n")
13
+ s.require_paths = ["lib"]
14
+
15
+ s.executables << 'gist'
16
+
17
+ s.add_dependency 'json'
18
+ %w(rake rspec webmock ronn).each do |gem|
19
+ s.add_development_dependency gem
20
+ end
21
+ end