-
Notifications
You must be signed in to change notification settings - Fork 18
/
jist
executable file
·134 lines (105 loc) · 4.03 KB
/
jist
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env ruby
require 'optparse'
require 'jist'
# For the holdings of options.
options = {}
filenames = []
opts = OptionParser.new do |opts|
executable_name = File.split($0)[1]
opts.banner = <<-EOS
Jist (v#{Jist::VERSION}) lets you upload to https://gist.github.com/
The content to be uploaded can be passed as a list of files, if none are
specified STDIN will be read. The default filename for STDIN is "a.rb", and all
filenames can be overridden by repeating the "-f" flag. The most useful reason
to do this is to change the syntax highlighting.
If you'd like your gists to be associated with your GitHub account, so that you
can edit them and find them in future, first use `jist --login` to obtain an
Oauth2 access token. This is stored and used by jist in the future.
Public gists have guessable URLs and can be created with "-p", you can also set
the description at the top of the gist by passing "-d".
Anonymous gists are not associated with your GitHub account, they can be created
with "-a" even after you have used "jist --login". If you already have an access
token with the "gist" scope, you can pass that with "-t".
If you would like to shorten the resulting gist URL, use the -s flag. This will
use GitHub's URL shortener, git.io.
To copy the resulting URL to your clipboard you can use the -c option, or to just
open it directly in your browser, use -o. Using the -j option will copy the embeddable
URL to the clipboard. You can add `alias jist='jist -c'` to your shell's rc file to configure this
behaviour by default.
Instead of creating a new jist, you can update an existing one by passing its ID
or URL with "-u". For this to work, you must be logged in, and have created the
original gist with the same GitHub account.
Usage: #{executable_name} [-o|-c|-j] [-p] [-s] [-d DESC] [-t TOKEN|-a] [-u URL] [-P] [-f NAME]* FILE*
#{executable_name} --login
EOS
opts.on("--login", "Authenticate jist on this computer.") do
Jist.login!
exit
end
opts.on("-f", "--filename [NAME.EXTENSION]", "Sets the filename and syntax type.") do |filename|
filenames << filename
options[:filename] = filename
end
opts.on("-p", "--public", "Makes your gist public.") do |public|
options[:public] = public
end
opts.on("-d", "--description DESCRIPTION", "Adds a description to your gist.") do |description|
options[:description] = description
end
opts.on("-s", "--shorten", "Shorten the gist URL using git.io.") do |shorten|
options[:shorten] = shorten
end
opts.on("-u", "--update [ URL | ID ]", "Update an existing gist.") do |update|
options[:update] = update
end
opts.on("-a", "--anonymous", "Create an anonymous gist.") do
options[:anonymous] = true
end
opts.on("-t", "--token OAUTH_TOKEN", "The OAuth2 access_token to use.") do |token|
options[:access_token] = token
end
opts.on("-c", "--copy", "Copy the resulting URL to the clipboard") do
options[:copy] = true
end
opts.on("-j", "--copy-js", "Copy the resulting embeddable URL to the clipboard") do
options[:copy_js] = true
end
opts.on("-o", "--open", "Open the resulting URL in a browser") do
options[:open] = true
end
opts.on("-P", "--paste", "Paste from the clipboard to jist") do
options[:paste] = true
end
opts.on_tail("-h","--help", "Show this message.") do
puts opts
exit
end
opts.on_tail("-v", "--version", "Print the version.") do
puts "jist v#{Jist::VERSION}"
exit
end
end
opts.parse!
begin
if options[:paste]
puts Jist.gist(Jist.paste, options)['html_url']
elsif ARGV.size == 0
$stderr.puts "(type a gist. <ctrl-c> to cancel, <ctrl-d> when done)" if $stdin.tty?
puts Jist.gist(ARGF.read, options)['html_url']
else
files = {}
ARGV.zip(filenames).each do |(file, name)|
files[name || file] = begin
File.read(File.expand_path(file))
rescue => e
raise e.extend(Jist::Error)
end
end
puts Jist.multi_gist(files, options)['html_url']
end
rescue Jist::Error => e
puts "Error: #{e.message}"
exit 1
rescue Interrupt
# bye!
end