ghcurl 0.6.0 → 0.7.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.
- checksums.yaml +4 -4
- data/README.md +45 -10
- data/bin/ghcurl +108 -71
- data/lib/ghcurl.rb +6 -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: efa8ec89c9537aeb042258adb82a8b4c5b5906fee9f75d1ac348bb59d98095a7
|
4
|
+
data.tar.gz: a95f9e3385e1bb9766c1b807520ae191f768801e83fffe29a7231a10f4926cf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1839ed2a13c403b71a7ea01773f7ec9b4b7b13b3a7f2aade2fa567703e46fb3b8b2b05395f17fa690924d93a8c570195b57d733768883f07b6f44aab58c5fb3
|
7
|
+
data.tar.gz: b37c28392213b7b0a73343b8fa61399d510edc3ff8fc51758e95e79c10bf30f7188851d3e5df53411b3275bee72980f5f6acf66aa69a3b4a8e57f5c3c6f8bd6b
|
data/README.md
CHANGED
@@ -4,21 +4,47 @@
|
|
4
4
|
|
5
5
|
[](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-26>
|
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,25 @@ module Ghcurl
|
|
37
35
|
end
|
38
36
|
|
39
37
|
|
40
|
-
|
41
|
-
|
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}"
|
42
54
|
system cmd
|
43
|
-
log "Downloaded to #{
|
55
|
+
log "Downloaded to #{to}"
|
56
|
+
return to
|
44
57
|
end
|
45
58
|
|
46
59
|
|
@@ -113,8 +126,11 @@ module Ghcurl
|
|
113
126
|
end
|
114
127
|
|
115
128
|
|
116
|
-
def download(repo, regexp, version: nil)
|
129
|
+
def download(repo, regexp, version: nil, download_to: nil)
|
130
|
+
|
131
|
+
require 'octokit'
|
117
132
|
|
133
|
+
# adjust repo name : user/repo
|
118
134
|
if repo =~ /^https:\/\/github.com/
|
119
135
|
require 'uri'
|
120
136
|
uri = URI(repo)
|
@@ -132,27 +148,32 @@ module Ghcurl
|
|
132
148
|
end
|
133
149
|
|
134
150
|
log "checking..."
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
151
|
+
begin
|
152
|
+
unless version
|
153
|
+
doc = Octokit::Client.new.latest_release(repo)
|
154
|
+
else
|
155
|
+
doc = Octokit::Client.new.release_for_tag(repo, 'v' + version)
|
156
|
+
end
|
157
|
+
rescue Octokit::NotFound
|
158
|
+
puts "ghcurl: Not found #{repo} v#{version} !"
|
159
|
+
rescue Error => e
|
160
|
+
puts e
|
161
|
+
exit 0
|
139
162
|
end
|
140
163
|
|
141
|
-
|
142
|
-
links = doc.css("li>a[href^='/#{repo}/releases/download']")
|
164
|
+
links = doc.to_hash[:assets]
|
143
165
|
if links.empty?
|
144
|
-
puts doc.css('li a').map(&:to_s)
|
145
166
|
log <<~EOE
|
146
|
-
The search result is empty, check the args
|
167
|
+
The search result is empty, check the args!
|
147
168
|
repo: #{repo}
|
148
169
|
version: #{version ? version:'nil'}
|
149
|
-
|
170
|
+
|
171
|
+
Maybe there's no assets in this release
|
150
172
|
EOE
|
151
|
-
|
173
|
+
exit 0
|
152
174
|
end
|
153
175
|
|
154
|
-
|
155
|
-
links = links.map { _1['href'] }
|
176
|
+
links = links.map { _1[:browser_download_url] }
|
156
177
|
|
157
178
|
|
158
179
|
if regexp
|
@@ -184,55 +205,58 @@ module Ghcurl
|
|
184
205
|
end
|
185
206
|
end
|
186
207
|
|
187
|
-
url =
|
208
|
+
url = links[0].split('/')[0..-2].join('/') + '/' + link
|
188
209
|
|
189
210
|
log "Downloading #{url}"
|
190
211
|
|
191
|
-
|
212
|
+
dl_name = link.split('/').last
|
192
213
|
|
193
|
-
curl(url,
|
194
|
-
return download_name
|
214
|
+
return curl(url, dl_name, download_to)
|
195
215
|
end
|
196
216
|
|
197
217
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
target = "#{WAREHOUSE}/#{dl_name}"
|
218
|
+
#
|
219
|
+
# This function is a little confusing
|
220
|
+
#
|
221
|
+
# target: The absolute path to a downloaded file
|
222
|
+
# name : The software name
|
223
|
+
#
|
224
|
+
def install(target, rename_as: nil, install_to: nil)
|
206
225
|
|
207
226
|
if target.end_with?('.deb')
|
208
|
-
log "Install deb package
|
227
|
+
log "Install the deb package"
|
209
228
|
system "sudo dpkg -i #{target}"
|
210
229
|
return
|
211
230
|
end
|
212
231
|
|
213
232
|
if target.end_with?('.rpm')
|
214
|
-
log "Install rpm package
|
233
|
+
log "Install the rpm package"
|
215
234
|
system "sudo rpm -i #{target}"
|
216
235
|
return
|
217
236
|
end
|
218
237
|
|
219
238
|
|
239
|
+
if install_to.nil?
|
240
|
+
install_to = BIN_PATH
|
241
|
+
end
|
242
|
+
|
243
|
+
|
220
244
|
#
|
221
|
-
#
|
245
|
+
# Handle zip situation
|
222
246
|
#
|
223
|
-
|
224
247
|
zip_flag = false
|
225
|
-
|
226
|
-
unzip_dir = ""
|
227
|
-
# unzipped files
|
228
|
-
files = ""
|
229
|
-
# our desired software name
|
230
|
-
name = ""
|
231
|
-
|
248
|
+
|
232
249
|
if target.match?(/\.zip$/) or target.match?(/\.tar\.(\w){1,3}/)
|
233
250
|
|
234
251
|
zip_flag = true
|
235
252
|
|
253
|
+
# unzipped to dir
|
254
|
+
unzip_dir = ""
|
255
|
+
# unzipped files
|
256
|
+
files = ""
|
257
|
+
# the target unzipped file name (this includes the path prefix)
|
258
|
+
unzip_name = ""
|
259
|
+
|
236
260
|
# unzip
|
237
261
|
if target.match? /\.zip$/
|
238
262
|
log "Unzip zip file"
|
@@ -249,7 +273,9 @@ module Ghcurl
|
|
249
273
|
end
|
250
274
|
|
251
275
|
|
252
|
-
|
276
|
+
#
|
277
|
+
# @return [Array] file names in the dir
|
278
|
+
#
|
253
279
|
def _iterate_dir(dir)
|
254
280
|
result = []
|
255
281
|
chd = Dir.children(dir)
|
@@ -266,28 +292,29 @@ module Ghcurl
|
|
266
292
|
end
|
267
293
|
|
268
294
|
|
269
|
-
|
270
295
|
Dir.chdir unzip_dir do
|
271
296
|
files = _iterate_dir('.')
|
272
297
|
end
|
273
298
|
|
274
299
|
|
275
300
|
if files.size > 1
|
276
|
-
|
301
|
+
unzip_name = HL.choose do |menu|
|
277
302
|
menu.index_color = :rgb_77bbff
|
278
303
|
menu.prompt = "Which one do you want to install? "
|
279
304
|
menu.choices( *files )
|
280
305
|
end
|
281
306
|
else
|
282
|
-
|
307
|
+
unzip_name = files[0]
|
283
308
|
end
|
284
309
|
|
285
310
|
end # end of zipped file handle
|
286
311
|
|
287
312
|
|
288
|
-
|
289
|
-
|
290
|
-
name =
|
313
|
+
# Get software real name
|
314
|
+
if zip_flag
|
315
|
+
name = unzip_name.split('/').last
|
316
|
+
else
|
317
|
+
name = target.split('/').last
|
291
318
|
end
|
292
319
|
|
293
320
|
|
@@ -302,29 +329,33 @@ module Ghcurl
|
|
302
329
|
end
|
303
330
|
end
|
304
331
|
|
305
|
-
|
332
|
+
|
306
333
|
if zip_flag
|
307
|
-
#
|
308
|
-
|
334
|
+
# Now:
|
335
|
+
# target is /home/xx/xx.zip
|
336
|
+
# unzip_dir is /home/xx/xx
|
337
|
+
# unzip_file is abc/cde/file (new target)
|
338
|
+
target = unzip_dir + '/' + unzip_name
|
309
339
|
end
|
310
340
|
|
311
|
-
if rename_as
|
312
|
-
log "Renamed as '#{rename_as}'"
|
313
|
-
end
|
341
|
+
log "Renamed as '#{rename_as}'" if rename_as
|
314
342
|
|
315
343
|
|
316
344
|
case RUBY_PLATFORM
|
317
345
|
when /ucrt/i, /mingw/i
|
318
|
-
install_on_windows(name, install_to, rename_as)
|
346
|
+
install_on_windows(target, name, install_to, rename_as)
|
319
347
|
else
|
320
|
-
install_on_nix(name, install_to, rename_as)
|
348
|
+
install_on_nix(target, name, install_to, rename_as)
|
321
349
|
end
|
322
350
|
end
|
323
351
|
|
324
352
|
|
325
|
-
|
326
|
-
|
327
|
-
|
353
|
+
#
|
354
|
+
# @param target [String] the absulute path of to be installed software
|
355
|
+
# @param name [String] the name of the software
|
356
|
+
#
|
357
|
+
def install_on_nix(target, name, install_to, rename_as)
|
358
|
+
install_to = install_to.chomp('/')
|
328
359
|
|
329
360
|
if test 'd', install_to
|
330
361
|
log "Ready to install #{name}"
|
@@ -346,7 +377,7 @@ module Ghcurl
|
|
346
377
|
end
|
347
378
|
|
348
379
|
|
349
|
-
def install_on_windows
|
380
|
+
def install_on_windows(target, name, install_to, rename_as)
|
350
381
|
log "Sorry, not implemented yet on Windows! Can you help?"
|
351
382
|
end
|
352
383
|
|
@@ -395,14 +426,15 @@ module Ghcurl
|
|
395
426
|
Default install to env 'GHCURL_BIN_PATH' or /usr/local/bin
|
396
427
|
|
397
428
|
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 -
|
429
|
+
ghcurl [user]/repo [regexp] => Search latest version with regexp to download
|
430
|
+
ghcurl repo [re] -v tag => Download a specific tag version
|
431
|
+
ghcurl repo [re] -o [path] => Download into path or rename
|
432
|
+
ghcurl repo [re] -i [path] => Download and install to path
|
433
|
+
ghcurl repo [re] -o [path] -i => Download into path and install
|
434
|
+
ghcurl repo [re] -i -r name => Download and install as 'name'
|
435
|
+
ghcurl -l => List downloaded files
|
436
|
+
ghcurl -d [name] => Delete a downloaded file or all
|
437
|
+
ghcurl -h => Print this help
|
406
438
|
|
407
439
|
example:
|
408
440
|
ghcurl bat => Search sharkdp/bat the latest
|
@@ -424,6 +456,7 @@ extend Ghcurl
|
|
424
456
|
|
425
457
|
class Ghcurl::CLI < CliSwitch
|
426
458
|
option name: 'install', short: '-i', arg_required: 'optional'
|
459
|
+
option name: 'output', short: '-o', long: '--output', arg_required: 'required'
|
427
460
|
option name: 'rename', short: '-r', arg_required: 'required'
|
428
461
|
option name: 'version', short: '-v', arg_required: 'required'
|
429
462
|
option name: 'help', short: '-h', long: '--help', arg_required: 'noarg'
|
@@ -442,6 +475,7 @@ end
|
|
442
475
|
repo_or_name, regexp = args[0], args[1]
|
443
476
|
version = nil
|
444
477
|
need_install = false
|
478
|
+
download_to = nil
|
445
479
|
install_to = nil
|
446
480
|
rename_as = nil
|
447
481
|
|
@@ -458,6 +492,8 @@ opts.each do
|
|
458
492
|
exit
|
459
493
|
when 'version'
|
460
494
|
version = _1.next_arg
|
495
|
+
when 'output'
|
496
|
+
download_to = _1.next_arg
|
461
497
|
when 'install'
|
462
498
|
need_install = true
|
463
499
|
install_to = _1.next_arg
|
@@ -470,13 +506,14 @@ end
|
|
470
506
|
# p repo_or_name
|
471
507
|
# p regexp
|
472
508
|
# p need_install
|
509
|
+
# p download_to
|
473
510
|
# p install_to
|
474
511
|
# p rename_as
|
475
512
|
|
476
513
|
begin
|
477
|
-
|
514
|
+
ware = download(repo_or_name, regexp, version: version, download_to: download_to)
|
478
515
|
if need_install
|
479
|
-
install(
|
516
|
+
install(ware, rename_as: rename_as, install_to: install_to)
|
480
517
|
end
|
481
518
|
rescue Interrupt
|
482
519
|
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-26>
|
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.7.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,7 @@ 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'
|
66
68
|
}
|
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.7.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-26 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
|