aapis-gist 5.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: de155e5b6b78a72f2bc342b68661bb1c82e2b6179af79867366e85c82306a92f
4
+ data.tar.gz: 7d502ea314446a558968602a6f261099b1223b3c1eef0a364286c03e8ef6a6ea
5
+ SHA512:
6
+ metadata.gz: 7ee0ce5a7eb966709ca415ce47209fbcb8b030f3812cc0c444d9ab3fc3b1b929f1e66c153faa0685ec5966e5c799f27b6f161d8807178ca65c3233bf94e5c16c
7
+ data.tar.gz: 8c1a82589d6d50c7dabfa8f2883ad8609e9fa2128b03aa59ca726cae2531b7b44dd3be4f7a0671678778698687e79c9e48e519f8796203a8966d949254c6e85b
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 'https://rubygems.org'
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,196 @@
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
+ ‌For OS X, gist lives in Homebrew
21
+
22
+ brew install gist
23
+
24
+ ‌For FreeBSD, gist lives in ports
25
+
26
+ pkg install gist
27
+
28
+
29
+ ## Command
30
+
31
+ ‌To upload the contents of `a.rb` just:
32
+
33
+ gist a.rb
34
+
35
+ ‌Upload multiple files:
36
+
37
+ gist a b c
38
+ gist *.rb
39
+
40
+ ‌By default it reads from STDIN, and you can set a filename with `-f`.
41
+
42
+ gist -f test.rb <a.rb
43
+
44
+ ‌Alternatively, you can just paste from the clipboard:
45
+
46
+ gist -P
47
+
48
+ ‌Use `-p` to make the gist private:
49
+
50
+ gist -p a.rb
51
+
52
+ ‌Use `-d` to add a description:
53
+
54
+ gist -d "Random rbx bug" a.rb
55
+
56
+ ‌You can update existing gists with `-u`:
57
+
58
+ gist -u GIST_ID FILE_NAME
59
+ gist -u 42f2c239d2eb57299408 test.txt
60
+
61
+ ‌If you'd like to copy the resulting URL to your clipboard, use `-c`.
62
+
63
+ gist -c <a.rb
64
+
65
+ ‌If you'd like to copy the resulting embeddable URL to your clipboard, use `-e`.
66
+
67
+ gist -e <a.rb
68
+
69
+ ‌And you can just ask gist to open a browser window directly with `-o`.
70
+
71
+ gist -o <a.rb
72
+
73
+ ‌To list (public gists or all gists for authed user) gists for user
74
+
75
+ gist -l : all gists for authed user
76
+ gist -l defunkt : list defunkt's public gists
77
+
78
+ To read a gist and print it to STDOUT
79
+
80
+ gist -r GIST_ID
81
+ gist -r 374130
82
+
83
+ ‌See `gist --help` for more detail.
84
+
85
+ ## Login
86
+
87
+ If you want to associate your gists with your GitHub account, you need to login
88
+ with gist. It doesn't store your username and password, it just uses them to get
89
+ an OAuth2 token (with the "gist" permission).
90
+
91
+ gist --login
92
+ Obtaining OAuth2 access_token from GitHub.
93
+ GitHub username: ConradIrwin
94
+ GitHub password:
95
+ 2-factor auth code:
96
+ Success! https://github.com/settings/tokens
97
+
98
+ This token is stored in `~/.gist` and used for all future gisting. If you need to
99
+ you can revoke it from https://github.com/settings/tokens, or just delete the
100
+ file.
101
+
102
+ #### Password-less login
103
+
104
+ If you have a complicated authorization requirement you can manually create a
105
+ token file by pasting a GitHub token with only the `gist` permission into a
106
+ file called `~/.gist`. You can create one from https://github.com/settings/tokens
107
+
108
+ This file should contain only the token (~40 hex characters), and to make it
109
+ easier to edit, can optionally have a final newline (`\n` or `\r\n`).
110
+
111
+ For example, one way to create this file would be to run:
112
+
113
+ (umask 0077 && echo MY_SECRET_TOKEN > ~/.gist)
114
+
115
+ The `umask` ensures that the file is only accessible from your user account.
116
+
117
+ ### GitHub Enterprise
118
+
119
+ If you'd like `gist` to use your locally installed [GitHub Enterprise](https://enterprise.github.com/),
120
+ you need to export the `GITHUB_URL` environment variable (usually done in your `~/.bashrc`).
121
+
122
+ export GITHUB_URL=http://github.internal.example.com/
123
+
124
+ Once you've done this and restarted your terminal (or run `source ~/.bashrc`), gist will
125
+ automatically use GitHub Enterprise instead of the public github.com
126
+
127
+ Your token for GitHub Enterprise will be stored in `.gist.<protocol>.<server.name>[.<port>]` (e.g.
128
+ `~/.gist.http.github.internal.example.com` for the GITHUB_URL example above) instead of `~/.gist`.
129
+
130
+ If you have multiple servers or use Enterprise and public GitHub often, you can work around this by creating scripts
131
+ 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
132
+ setting it to the public URL will not work. Use `unset GITHUB_URL`
133
+
134
+ ### Token file format
135
+
136
+ If you cannot use passwords, as most Enterprise installations do, you can generate the token via the web interface
137
+ and then simply save the string in the correct file. Avoid line breaks or you might see:
138
+ ```
139
+ $ gist -l
140
+ Error: Bad credentials
141
+ ```
142
+
143
+ # Library
144
+
145
+ ‌You can also use Gist as a library from inside your ruby code:
146
+
147
+ Gist.gist("Look.at(:my => 'awesome').code")
148
+
149
+ If you need more advanced features you can also pass:
150
+
151
+ * `:access_token` to authenticate using OAuth2 (default is `File.read("~/.gist")).
152
+ * `:filename` to change the syntax highlighting (default is `a.rb`).
153
+ * `:public` if you want your gist to have a guessable url.
154
+ * `:description` to add a description to your gist.
155
+ * `:update` to update an existing gist (can be a URL or an id).
156
+ * `:copy` to copy the resulting URL to the clipboard (default is false).
157
+ * `:open` to open the resulting URL in a browser (default is false).
158
+
159
+ NOTE: The access_token must have the "gist" scope.
160
+
161
+ ‌If you want to upload multiple files in the same gist, you can:
162
+
163
+ Gist.multi_gist("a.rb" => "Foo.bar", "a.py" => "Foo.bar")
164
+
165
+ ‌If you'd rather use gist's builtin access_token, then you can force the user
166
+ to obtain one by calling:
167
+
168
+ Gist.login!
169
+
170
+ ‌This will take them through the process of obtaining an OAuth2 token, and storing it
171
+ in `~/.gist`, where it can later be read by `Gist.gist`
172
+
173
+ ## Configuration
174
+
175
+ ‌If you'd like `-o` or `-c` to be the default when you use the gist executable, add an
176
+ alias to your `~/.bashrc` (or equivalent). For example:
177
+
178
+ alias gist='gist -c'
179
+
180
+ ‌If you'd prefer gist to open a different browser, then you can export the BROWSER
181
+ environment variable:
182
+
183
+ export BROWSER=google-chrome
184
+
185
+ If clipboard or browser integration don't work on your platform, please file a bug or
186
+ (more ideally) a pull request.
187
+
188
+ If you need to use an HTTP proxy to access the internet, export the `HTTP_PROXY` or
189
+ `http_proxy` environment variable and gist will use it.
190
+
191
+ ## Meta-fu
192
+
193
+ Thanks to @defunkt and @indirect for writing and maintaining versions 1 through 3.
194
+ Thanks to @rking and @ConradIrwin for maintaining version 4.
195
+
196
+ 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,211 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Silence Ctrl-C's
4
+ trap('INT'){ exit 1 }
5
+
6
+ if Signal.list.include? 'PIPE'
7
+ trap('PIPE', 'EXIT')
8
+ end
9
+
10
+ require 'optparse'
11
+ require 'gist'
12
+
13
+ # For the holdings of options.
14
+ options = {}
15
+ filenames = []
16
+
17
+ OptionParser.new do |opts|
18
+ executable_name = File.split($0)[1]
19
+ opts.banner = <<-EOS
20
+ Gist (v#{Gist::VERSION}) lets you upload to https://gist.github.com/
21
+
22
+ The content to be uploaded can be passed as a list of files, if none are
23
+ specified STDIN will be read. The default filename for STDIN is "a.rb", and all
24
+ filenames can be overridden by repeating the "-f" flag. The most useful reason
25
+ to do this is to change the syntax highlighting.
26
+
27
+ All gists must to be associated with a GitHub account, so you will need to login with
28
+ `gist --login` to obtain an OAuth2 access token. This is stored and used by gist in the future.
29
+
30
+ Private gists do not have guessable URLs and can be created with "-p", you can
31
+ also set the description at the top of the gist by passing "-d".
32
+
33
+ If you would like to shorten the resulting gist URL, use the -s flag. This will
34
+ use GitHub's URL shortener, git.io. You can also use -R to get the link to the
35
+ raw gist.
36
+
37
+ To copy the resulting URL to your clipboard you can use the -c option, or to
38
+ just open it directly in your browser, use -o. Using the -e option will copy the
39
+ embeddable URL to the clipboard. You can add `alias gist='gist -c'` to your
40
+ shell's rc file to configure this behaviour by default.
41
+
42
+ Instead of creating a new gist, you can update an existing one by passing its ID
43
+ or URL with "-u". For this to work, you must be logged in, and have created the
44
+ original gist with the same GitHub account.
45
+
46
+ If you want to skip empty files, use the --skip-empty flag. If all files are
47
+ empty no gist will be created.
48
+
49
+ Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-u URL]
50
+ [--skip-empty] [-P] [-f NAME|-t EXT]* FILE*
51
+ #{executable_name} --login
52
+ #{executable_name} [-l|-r]
53
+
54
+ EOS
55
+
56
+ opts.on("--login", "Authenticate gist on this computer.") do
57
+ Gist.login!
58
+ exit
59
+ end
60
+
61
+ opts.on("-f", "--filename [NAME.EXTENSION]", "Sets the filename and syntax type.") do |filename|
62
+ filenames << filename
63
+ options[:filename] = filename
64
+ end
65
+
66
+ opts.on("-t", "--type [EXTENSION]", "Sets the file extension and syntax type.") do |extension|
67
+ filenames << "foo.#{extension}"
68
+ options[:filename] = "foo.#{extension}"
69
+ end
70
+
71
+ opts.on("-p", "--private", "Makes your gist private.") do
72
+ options[:private] = true
73
+ end
74
+
75
+ opts.on("--no-private") do
76
+ options[:private] = false
77
+ end
78
+
79
+ opts.on("-d", "--description DESCRIPTION", "Adds a description to your gist.") do |description|
80
+ options[:description] = description
81
+ end
82
+
83
+ opts.on("-s", "--shorten", "Shorten the gist URL using git.io.") do |shorten|
84
+ options[:shorten] = shorten
85
+ end
86
+
87
+ opts.on("-u", "--update [ URL | ID ]", "Update an existing gist.") do |update|
88
+ options[:update] = update
89
+ end
90
+
91
+ opts.on("-c", "--copy", "Copy the resulting URL to the clipboard") do
92
+ options[:copy] = true
93
+ end
94
+
95
+ opts.on("-e", "--embed", "Copy the embed code for the gist to the clipboard") do
96
+ options[:embed] = true
97
+ options[:copy] = true
98
+ end
99
+
100
+ opts.on("-o", "--open", "Open the resulting URL in a browser") do
101
+ options[:open] = true
102
+ end
103
+
104
+ opts.on("--no-open")
105
+
106
+ opts.on("--skip-empty", "Skip gisting empty files") do
107
+ options[:skip_empty] = true
108
+ end
109
+
110
+ opts.on("-P", "--paste", "Paste from the clipboard to gist") do
111
+ options[:paste] = true
112
+ end
113
+
114
+ opts.on("-R", "--raw", "Display raw URL of the new gist") do
115
+ options[:raw] = true
116
+ end
117
+
118
+ opts.on("-l", "--list [USER]", "List all gists for user") do |user|
119
+ options[:list] = user
120
+ end
121
+
122
+ opts.on("-r", "--read ID [FILENAME]", "Read a gist and print out the contents") do |id|
123
+ options[:read] = id
124
+ end
125
+
126
+ opts.on("--delete [ URL | ID ]", "Delete a gist") do |id|
127
+ options[:delete] = id
128
+ end
129
+
130
+ opts.on_tail("-h","--help", "Show this message.") do
131
+ puts opts
132
+ exit
133
+ end
134
+
135
+ opts.on_tail("-v", "--version", "Print the version.") do
136
+ puts "gist v#{Gist::VERSION}"
137
+ exit
138
+ end
139
+
140
+ end.parse!
141
+
142
+ begin
143
+ if Gist.auth_token.nil?
144
+ puts 'Please log in with `gist --login`. ' \
145
+ '(GitHub now requires credentials to gist https://bit.ly/2GBBxKw)'
146
+ exit(1)
147
+ end
148
+
149
+ options[:output] = if options[:embed] && options[:shorten]
150
+ raise Gist::Error, "--embed does not make sense with --shorten"
151
+ elsif options[:embed]
152
+ :javascript
153
+ elsif options[:shorten] and options[:raw]
154
+ :short_raw_url
155
+ elsif options[:shorten]
156
+ :short_url
157
+ elsif options[:raw]
158
+ :raw_url
159
+ else
160
+ :html_url
161
+ end
162
+
163
+ options[:public] = Gist.should_be_public?(options)
164
+
165
+ if options.key? :list
166
+ if options[:list]
167
+ Gist.list_all_gists(options[:list])
168
+ else
169
+ Gist.list_all_gists
170
+ end
171
+ exit
172
+ end
173
+
174
+ if options.key? :read
175
+ file_name = ARGV.first
176
+ Gist.read_gist(options[:read], file_name)
177
+ exit
178
+ end
179
+
180
+ if options.key? :delete
181
+ Gist.delete_gist(options[:delete])
182
+ exit
183
+ end
184
+
185
+ if options[:paste]
186
+ puts Gist.gist(Gist.paste, options)
187
+ else
188
+ to_read = ARGV.empty? ? ['-'] : ARGV
189
+ files = {}
190
+ to_read.zip(filenames).each do |(file, name)|
191
+ files[name || file] =
192
+ begin
193
+ if file == '-'
194
+ $stderr.puts "(type a gist. <ctrl-c> to cancel, <ctrl-d> when done)" if $stdin.tty?
195
+ STDIN.read
196
+ else
197
+ File.read(File.expand_path(file))
198
+ end
199
+ rescue => e
200
+ raise e.extend(Gist::Error)
201
+ end
202
+ end
203
+
204
+ output = Gist.multi_gist(files, options)
205
+ puts output if output
206
+ end
207
+
208
+ rescue Gist::Error => e
209
+ puts "Error: #{e.message}"
210
+ exit 1
211
+ end