ghcurl 0.6.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +45 -10
- data/bin/ghcurl +116 -73
- data/lib/ghcurl.rb +9 -4
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2238b90c3f61619eb9f28f29ed7f8c877ef524936e394511e95fd9fd239142e
|
4
|
+
data.tar.gz: '0821dc3f69cc443c42d18200c8c92a60415d8bac045de7ac4388e814e08ecca5'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5c5f13aa7f4a10e5a06daf7bcf3f580ef4f2d05ba0d62bf7ddbcc433f6f840f3fe9027557ee24cb5bcf25a0b9eb2ce2ed3afe6cc412cd5efd1454246cb3a346
|
7
|
+
data.tar.gz: cb845d8d93fdcbc324a2fa3fa3f037049c7e95852c77746ff00207c34839eda761c6e3b84d5723c0052c6d7ec1392b265c3da092b0ba8f70b89135c0bb5d4022
|
data/README.md
CHANGED
@@ -4,21 +4,47 @@
|
|
4
4
|
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/ghcurl.svg)](https://rubygems.org/gems/ghcurl)
|
6
6
|
|
7
|
+
|
8
|
+
Download files and install from Github releases.
|
9
|
+
|
7
10
|
```bash
|
8
11
|
gem install ghcurl
|
9
12
|
```
|
10
13
|
|
14
|
+
</div>
|
15
|
+
|
16
|
+
`ghcurl` can recognize your OS and arch, give you the proper option to download. You can search by regular expression, specify a version, and install it to a path or according to the environment variable `GHCURL_BIN_PATH` or just `/usr/local/bin`. It will automatically extract a tar/zip file to make the installation process better.
|
17
|
+
|
18
|
+
Note it doesn't work on Windows.
|
19
|
+
|
11
20
|
<br>
|
12
21
|
|
13
|
-
|
22
|
+
## Usage
|
14
23
|
|
15
|
-
|
24
|
+
```bash
|
25
|
+
$ ghcurl [user/]repo [regexp] [options]
|
26
|
+
```
|
16
27
|
|
17
|
-
|
28
|
+
**-o**
|
18
29
|
|
19
|
-
|
30
|
+
This is optional, download will default to `~/.cache/ghcurl`
|
31
|
+
1. `-o path` Download into path
|
32
|
+
2. `-o path/name` Download as path/name
|
20
33
|
|
21
|
-
|
34
|
+
**-v**
|
35
|
+
1. `-v 1.0.0` Download tag version 1.0.0
|
36
|
+
2. `-v3.1.4` This is also OK to download tag version 3.1.4
|
37
|
+
|
38
|
+
**-i**
|
39
|
+
1. `-i` Install to `/usr/local/bin` or `GHCURL_BIN_PATH`
|
40
|
+
2. `-i path` Install to path
|
41
|
+
|
42
|
+
**-r**
|
43
|
+
1. `-r name` Install the binary as name
|
44
|
+
|
45
|
+
<br>
|
46
|
+
|
47
|
+
## Example
|
22
48
|
|
23
49
|
Things can be easier. We consider these as popular binaries: https://github.com/ibraheemdev/modern-unix
|
24
50
|
|
@@ -28,11 +54,11 @@ Notice: `-i` means to install.
|
|
28
54
|
# It knows that's sharkdp/fd
|
29
55
|
ghcurl fd -i
|
30
56
|
|
57
|
+
# It's cli/cli !
|
58
|
+
ghcurl gh -i
|
59
|
+
|
31
60
|
# Much easier to install rbspy!
|
32
61
|
ghcurl rbspy -i
|
33
|
-
|
34
|
-
# On Linux, it's very handy
|
35
|
-
ghcurl cli -i
|
36
62
|
```
|
37
63
|
|
38
64
|
Download latest deb/rpm package and install, notice the argument `deb` / `rpm` are just regular expressions.
|
@@ -43,6 +69,12 @@ ghcurl cli/cli rpm -i
|
|
43
69
|
|
44
70
|
Normal download
|
45
71
|
```bash
|
72
|
+
# The easiest way to download
|
73
|
+
ghcurl gh
|
74
|
+
|
75
|
+
# Download to /tmp
|
76
|
+
ghcurl gh -o /tmp
|
77
|
+
|
46
78
|
# Download latest rbspy-x86_64-unknown-linux-gnu.tar.gz to ~/.cache/ghcurl
|
47
79
|
ghcurl rbspy/rbspy 'x86_64.*linux'
|
48
80
|
|
@@ -53,10 +85,13 @@ ghcurl rbspy/rbspy 'x86_64.*linux' -v0.11.1
|
|
53
85
|
Download a binary and install it to anywhere
|
54
86
|
```bash
|
55
87
|
# Install to /usr/local/bin
|
56
|
-
ghcurl
|
88
|
+
ghcurl starship linux-gnu -i
|
57
89
|
|
58
90
|
# Install to ~/tmp/bin
|
59
|
-
ghcurl BetaPictoris/timeleft
|
91
|
+
ghcurl BetaPictoris/timeleft -i ~/tmp/bin
|
92
|
+
|
93
|
+
# Download as /tmp/github-cli and install
|
94
|
+
ghcurl gh -o /tmp/github-cli -i
|
60
95
|
|
61
96
|
# Install and rename it to, here, 'gd' in /usr/local/bin
|
62
97
|
ghcurl dlvhdr/gh-dash linux-amd64 -i -r 'gd'
|
data/bin/ghcurl
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# File : ghcurl.rb
|
4
4
|
# Authors : ccmywish <ccmywish@qq.com>
|
5
5
|
# Created on : <2022-04-12>
|
6
|
-
# Last modified : <2022-04-
|
6
|
+
# Last modified : <2022-04-29>
|
7
7
|
#
|
8
8
|
# ghcurl:
|
9
9
|
#
|
@@ -12,8 +12,6 @@
|
|
12
12
|
# ------------------------------------------------------
|
13
13
|
|
14
14
|
require 'ghcurl'
|
15
|
-
require 'nokogiri'
|
16
|
-
require 'open-uri'
|
17
15
|
require 'highline'
|
18
16
|
require 'cliswitch'
|
19
17
|
require 'fileutils'
|
@@ -37,10 +35,29 @@ module Ghcurl
|
|
37
35
|
end
|
38
36
|
|
39
37
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
#
|
39
|
+
# @return absolute download path
|
40
|
+
#
|
41
|
+
def curl(url, name, to)
|
42
|
+
if to == nil
|
43
|
+
to = WAREHOUSE + '/' + name
|
44
|
+
elsif test 'd', to
|
45
|
+
to = to.chomp('/') + '/' + name
|
46
|
+
elsif to.include?('/')
|
47
|
+
# noop
|
48
|
+
else
|
49
|
+
# just a rename in WAREHOUSE
|
50
|
+
to = WAREHOUSE + '/' + name
|
51
|
+
end
|
52
|
+
|
53
|
+
cmd = "curl -L #{url} --create-dirs -o #{to}"
|
54
|
+
status = system cmd
|
55
|
+
if status == false || status.nil?
|
56
|
+
log "Download error!"
|
57
|
+
exit
|
58
|
+
end
|
59
|
+
log "Downloaded to #{to}"
|
60
|
+
return to
|
44
61
|
end
|
45
62
|
|
46
63
|
|
@@ -113,8 +130,11 @@ module Ghcurl
|
|
113
130
|
end
|
114
131
|
|
115
132
|
|
116
|
-
def download(repo, regexp, version: nil)
|
133
|
+
def download(repo, regexp, version: nil, download_to: nil)
|
117
134
|
|
135
|
+
require 'octokit'
|
136
|
+
|
137
|
+
# adjust repo name : user/repo
|
118
138
|
if repo =~ /^https:\/\/github.com/
|
119
139
|
require 'uri'
|
120
140
|
uri = URI(repo)
|
@@ -132,27 +152,33 @@ module Ghcurl
|
|
132
152
|
end
|
133
153
|
|
134
154
|
log "checking..."
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
155
|
+
begin
|
156
|
+
unless version
|
157
|
+
doc = Octokit::Client.new.latest_release(repo)
|
158
|
+
else
|
159
|
+
doc = Octokit::Client.new.release_for_tag(repo, 'v' + version)
|
160
|
+
end
|
161
|
+
rescue Octokit::NotFound
|
162
|
+
log "Not found #{repo} v#{version} !"
|
163
|
+
exit
|
164
|
+
rescue StandardError => e
|
165
|
+
log e
|
166
|
+
exit
|
139
167
|
end
|
140
168
|
|
141
|
-
|
142
|
-
links = doc.css("li>a[href^='/#{repo}/releases/download']")
|
169
|
+
links = doc.to_hash[:assets]
|
143
170
|
if links.empty?
|
144
|
-
puts doc.css('li a').map(&:to_s)
|
145
171
|
log <<~EOE
|
146
|
-
The search result is empty, check the args
|
172
|
+
The search result is empty, check the args!
|
147
173
|
repo: #{repo}
|
148
174
|
version: #{version ? version:'nil'}
|
149
|
-
|
175
|
+
|
176
|
+
Maybe there's no assets in this release
|
150
177
|
EOE
|
151
|
-
|
178
|
+
exit 0
|
152
179
|
end
|
153
180
|
|
154
|
-
|
155
|
-
links = links.map { _1['href'] }
|
181
|
+
links = links.map { _1[:browser_download_url] }
|
156
182
|
|
157
183
|
|
158
184
|
if regexp
|
@@ -184,55 +210,58 @@ module Ghcurl
|
|
184
210
|
end
|
185
211
|
end
|
186
212
|
|
187
|
-
url =
|
213
|
+
url = links[0].split('/')[0..-2].join('/') + '/' + link
|
188
214
|
|
189
215
|
log "Downloading #{url}"
|
190
216
|
|
191
|
-
|
217
|
+
dl_name = link.split('/').last
|
192
218
|
|
193
|
-
curl(url,
|
194
|
-
return download_name
|
219
|
+
return curl(url, dl_name, download_to)
|
195
220
|
end
|
196
221
|
|
197
222
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
target = "#{WAREHOUSE}/#{dl_name}"
|
223
|
+
#
|
224
|
+
# This function is a little confusing
|
225
|
+
#
|
226
|
+
# target: The absolute path to a downloaded file
|
227
|
+
# name : The software name
|
228
|
+
#
|
229
|
+
def install(target, rename_as: nil, install_to: nil)
|
206
230
|
|
207
231
|
if target.end_with?('.deb')
|
208
|
-
log "Install deb package
|
232
|
+
log "Install the deb package"
|
209
233
|
system "sudo dpkg -i #{target}"
|
210
234
|
return
|
211
235
|
end
|
212
236
|
|
213
237
|
if target.end_with?('.rpm')
|
214
|
-
log "Install rpm package
|
238
|
+
log "Install the rpm package"
|
215
239
|
system "sudo rpm -i #{target}"
|
216
240
|
return
|
217
241
|
end
|
218
242
|
|
219
243
|
|
244
|
+
if install_to.nil?
|
245
|
+
install_to = BIN_PATH
|
246
|
+
end
|
247
|
+
|
248
|
+
|
220
249
|
#
|
221
|
-
#
|
250
|
+
# Handle zip situation
|
222
251
|
#
|
223
|
-
|
224
252
|
zip_flag = false
|
225
|
-
|
226
|
-
unzip_dir = ""
|
227
|
-
# unzipped files
|
228
|
-
files = ""
|
229
|
-
# our desired software name
|
230
|
-
name = ""
|
231
|
-
|
253
|
+
|
232
254
|
if target.match?(/\.zip$/) or target.match?(/\.tar\.(\w){1,3}/)
|
233
255
|
|
234
256
|
zip_flag = true
|
235
257
|
|
258
|
+
# unzipped to dir
|
259
|
+
unzip_dir = ""
|
260
|
+
# unzipped files
|
261
|
+
files = ""
|
262
|
+
# the target unzipped file name (this includes the path prefix)
|
263
|
+
unzip_name = ""
|
264
|
+
|
236
265
|
# unzip
|
237
266
|
if target.match? /\.zip$/
|
238
267
|
log "Unzip zip file"
|
@@ -249,7 +278,9 @@ module Ghcurl
|
|
249
278
|
end
|
250
279
|
|
251
280
|
|
252
|
-
|
281
|
+
#
|
282
|
+
# @return [Array] file names in the dir
|
283
|
+
#
|
253
284
|
def _iterate_dir(dir)
|
254
285
|
result = []
|
255
286
|
chd = Dir.children(dir)
|
@@ -266,28 +297,29 @@ module Ghcurl
|
|
266
297
|
end
|
267
298
|
|
268
299
|
|
269
|
-
|
270
300
|
Dir.chdir unzip_dir do
|
271
301
|
files = _iterate_dir('.')
|
272
302
|
end
|
273
303
|
|
274
304
|
|
275
305
|
if files.size > 1
|
276
|
-
|
306
|
+
unzip_name = HL.choose do |menu|
|
277
307
|
menu.index_color = :rgb_77bbff
|
278
308
|
menu.prompt = "Which one do you want to install? "
|
279
309
|
menu.choices( *files )
|
280
310
|
end
|
281
311
|
else
|
282
|
-
|
312
|
+
unzip_name = files[0]
|
283
313
|
end
|
284
314
|
|
285
315
|
end # end of zipped file handle
|
286
316
|
|
287
317
|
|
288
|
-
|
289
|
-
|
290
|
-
name =
|
318
|
+
# Get software real name
|
319
|
+
if zip_flag
|
320
|
+
name = unzip_name.split('/').last
|
321
|
+
else
|
322
|
+
name = target.split('/').last
|
291
323
|
end
|
292
324
|
|
293
325
|
|
@@ -302,29 +334,33 @@ module Ghcurl
|
|
302
334
|
end
|
303
335
|
end
|
304
336
|
|
305
|
-
|
337
|
+
|
306
338
|
if zip_flag
|
307
|
-
#
|
308
|
-
|
339
|
+
# Now:
|
340
|
+
# target is /home/xx/xx.zip
|
341
|
+
# unzip_dir is /home/xx/xx
|
342
|
+
# unzip_file is abc/cde/file (new target)
|
343
|
+
target = unzip_dir + '/' + unzip_name
|
309
344
|
end
|
310
345
|
|
311
|
-
if rename_as
|
312
|
-
log "Renamed as '#{rename_as}'"
|
313
|
-
end
|
346
|
+
log "Renamed as '#{rename_as}'" if rename_as
|
314
347
|
|
315
348
|
|
316
349
|
case RUBY_PLATFORM
|
317
350
|
when /ucrt/i, /mingw/i
|
318
|
-
install_on_windows(name, install_to, rename_as)
|
351
|
+
install_on_windows(target, name, install_to, rename_as)
|
319
352
|
else
|
320
|
-
install_on_nix(name, install_to, rename_as)
|
353
|
+
install_on_nix(target, name, install_to, rename_as)
|
321
354
|
end
|
322
355
|
end
|
323
356
|
|
324
357
|
|
325
|
-
|
326
|
-
|
327
|
-
|
358
|
+
#
|
359
|
+
# @param target [String] the absulute path of to be installed software
|
360
|
+
# @param name [String] the name of the software
|
361
|
+
#
|
362
|
+
def install_on_nix(target, name, install_to, rename_as)
|
363
|
+
install_to = install_to.chomp('/')
|
328
364
|
|
329
365
|
if test 'd', install_to
|
330
366
|
log "Ready to install #{name}"
|
@@ -346,7 +382,7 @@ module Ghcurl
|
|
346
382
|
end
|
347
383
|
|
348
384
|
|
349
|
-
def install_on_windows
|
385
|
+
def install_on_windows(target, name, install_to, rename_as)
|
350
386
|
log "Sorry, not implemented yet on Windows! Can you help?"
|
351
387
|
end
|
352
388
|
|
@@ -355,6 +391,7 @@ module Ghcurl
|
|
355
391
|
# For -l option
|
356
392
|
#
|
357
393
|
def list_wares
|
394
|
+
FileUtils.mkdir_p(WAREHOUSE)
|
358
395
|
puts blue("ghcurl: #{WAREHOUSE}")
|
359
396
|
Dir.children(WAREHOUSE).each_with_index do |dict,i|
|
360
397
|
puts "#{blue(i+1)}. #{bold(green(dict))}"
|
@@ -369,7 +406,7 @@ module Ghcurl
|
|
369
406
|
begin
|
370
407
|
|
371
408
|
if name.nil?
|
372
|
-
re = HL.ask "Do you want to delete all downloaded files?"
|
409
|
+
re = HL.ask "Do you want to delete all downloaded files?[Enter to yes or n]"
|
373
410
|
case re.downcase
|
374
411
|
when '','y','ye','yes','true'
|
375
412
|
FileUtils.rm_rf WAREHOUSE
|
@@ -395,14 +432,15 @@ module Ghcurl
|
|
395
432
|
Default install to env 'GHCURL_BIN_PATH' or /usr/local/bin
|
396
433
|
|
397
434
|
usage:
|
398
|
-
ghcurl [user]/repo [regexp]
|
399
|
-
ghcurl repo [re] -v tag
|
400
|
-
ghcurl repo [
|
401
|
-
ghcurl repo [re] -i [path]
|
402
|
-
ghcurl repo [re] -
|
403
|
-
ghcurl -
|
404
|
-
ghcurl -
|
405
|
-
ghcurl -
|
435
|
+
ghcurl [user]/repo [regexp] => Search latest version with regexp to download
|
436
|
+
ghcurl repo [re] -v tag => Download a specific tag version
|
437
|
+
ghcurl repo [re] -o [path] => Download into path or rename
|
438
|
+
ghcurl repo [re] -i [path] => Download and install to path
|
439
|
+
ghcurl repo [re] -o [path] -i => Download into path and install
|
440
|
+
ghcurl repo [re] -i -r name => Download and install as 'name'
|
441
|
+
ghcurl -l => List downloaded files
|
442
|
+
ghcurl -d [name] => Delete a downloaded file or all
|
443
|
+
ghcurl -h => Print this help
|
406
444
|
|
407
445
|
example:
|
408
446
|
ghcurl bat => Search sharkdp/bat the latest
|
@@ -424,6 +462,7 @@ extend Ghcurl
|
|
424
462
|
|
425
463
|
class Ghcurl::CLI < CliSwitch
|
426
464
|
option name: 'install', short: '-i', arg_required: 'optional'
|
465
|
+
option name: 'output', short: '-o', long: '--output', arg_required: 'required'
|
427
466
|
option name: 'rename', short: '-r', arg_required: 'required'
|
428
467
|
option name: 'version', short: '-v', arg_required: 'required'
|
429
468
|
option name: 'help', short: '-h', long: '--help', arg_required: 'noarg'
|
@@ -442,6 +481,7 @@ end
|
|
442
481
|
repo_or_name, regexp = args[0], args[1]
|
443
482
|
version = nil
|
444
483
|
need_install = false
|
484
|
+
download_to = nil
|
445
485
|
install_to = nil
|
446
486
|
rename_as = nil
|
447
487
|
|
@@ -458,6 +498,8 @@ opts.each do
|
|
458
498
|
exit
|
459
499
|
when 'version'
|
460
500
|
version = _1.next_arg
|
501
|
+
when 'output'
|
502
|
+
download_to = _1.next_arg
|
461
503
|
when 'install'
|
462
504
|
need_install = true
|
463
505
|
install_to = _1.next_arg
|
@@ -470,13 +512,14 @@ end
|
|
470
512
|
# p repo_or_name
|
471
513
|
# p regexp
|
472
514
|
# p need_install
|
515
|
+
# p download_to
|
473
516
|
# p install_to
|
474
517
|
# p rename_as
|
475
518
|
|
476
519
|
begin
|
477
|
-
|
520
|
+
ware = download(repo_or_name, regexp, version: version, download_to: download_to)
|
478
521
|
if need_install
|
479
|
-
install(
|
522
|
+
install(ware, rename_as: rename_as, install_to: install_to)
|
480
523
|
end
|
481
524
|
rescue Interrupt
|
482
525
|
end
|
data/lib/ghcurl.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
# File : ghcurl.rb
|
3
3
|
# Authors : ccmywish <ccmywish@qq.com>
|
4
4
|
# Created on : <2022-04-12>
|
5
|
-
# Last modified : <2022-04-
|
5
|
+
# Last modified : <2022-04-29>
|
6
6
|
#
|
7
7
|
# ghcurl:
|
8
8
|
#
|
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
module Ghcurl
|
14
14
|
|
15
|
-
VERSION = "0.
|
15
|
+
VERSION = "0.8.0"
|
16
16
|
|
17
17
|
end
|
18
18
|
|
@@ -24,6 +24,7 @@ end
|
|
24
24
|
Ghcurl::DEFAULT_WARES = {
|
25
25
|
|
26
26
|
cli: 'cli/cli',
|
27
|
+
gh: 'cli/cli',
|
27
28
|
|
28
29
|
fd: 'sharkdp/fd',
|
29
30
|
bat: 'sharkdp/bat',
|
@@ -61,6 +62,10 @@ Ghcurl::DEFAULT_WARES = {
|
|
61
62
|
xh: 'ducaale/xh',
|
62
63
|
zoxide: 'ajeetdsouza/zoxide',
|
63
64
|
|
64
|
-
scc:
|
65
|
-
rbspy:
|
65
|
+
scc: 'boyter/scc',
|
66
|
+
rbspy: 'rbspy/rbspy',
|
67
|
+
starship: 'starship/starship',
|
68
|
+
|
69
|
+
glow: 'charmbracelet/glow'
|
70
|
+
|
66
71
|
}
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ghcurl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ccmywish
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: octokit
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.22'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.22'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: highline
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|