ghcurl 0.4.0 → 0.5.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 +0 -18
- data/bin/ghcurl +197 -60
- data/lib/ghcurl.rb +65 -0
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b4840d95efdb75df9837f357689f9a4e1de17d22149d95a0843d26925923341
|
4
|
+
data.tar.gz: 13f087583da4f41ff0e94be251e74fe565981e8c01e73867a1be0e25ab88065f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be2b7c9bd8de0b137d8bdd07d49bdb9a30a3906e8034e87ac850047809ba2ec6dc24909b82feed5a53550532001222c0ae999e7441af27322c9ea34d18930289
|
7
|
+
data.tar.gz: 19d2d408baa93e56c2ce1145b7e2319283f9a18053f0cadf1fe46c9d4139356a7802794c534d5a4b6362189884e0089b2b0248781d800896e550cec1ea2e10a7
|
data/README.md
CHANGED
@@ -47,21 +47,3 @@ ghcurl dlvhdr/gh-dash linux-amd64 -i ~/tmp/bin/gd
|
|
47
47
|
```
|
48
48
|
|
49
49
|
<br>
|
50
|
-
|
51
|
-
## How does it works?
|
52
|
-
|
53
|
-
For future contributers and myself, I'll tell you how to maintain this.
|
54
|
-
|
55
|
-
In `ghcurl` previous to `0.3.1`, I write this code piece:
|
56
|
-
```ruby
|
57
|
-
unless version
|
58
|
-
# Notice: releases/tag/vx.x.x/download not works!!!
|
59
|
-
# This is a link relocation
|
60
|
-
url = "https://github.com/#{repo}/releases/latest/download/#{ware}"
|
61
|
-
else
|
62
|
-
# The real download link
|
63
|
-
url = "https://github.com/#{repo}/releases/download/v#{version}/#{ware}"
|
64
|
-
end
|
65
|
-
```
|
66
|
-
|
67
|
-
As you can see, it considers the Github router when you try to install a **latest** one, which are very unreliable, and you should specify a precise name for the thing you want to download. So from `0.4.0` I changed this via a slow but useful method: check the HTML file in the release page, and search the string user request which is not necessarily accurate, to find the download link directly.
|
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-14>
|
7
7
|
#
|
8
8
|
# ghcurl:
|
9
9
|
#
|
@@ -11,15 +11,18 @@
|
|
11
11
|
#
|
12
12
|
# ------------------------------------------------------
|
13
13
|
|
14
|
+
require 'ghcurl'
|
14
15
|
require 'nokogiri'
|
15
16
|
require 'open-uri'
|
17
|
+
require 'highline'
|
18
|
+
require 'cliswitch'
|
16
19
|
|
17
20
|
module Ghcurl
|
18
21
|
|
19
|
-
VERSION = "0.4.0"
|
20
22
|
WAREHOUSE = File.expand_path("~/.cache/ghcurl")
|
21
|
-
BIN_PATH = "/usr/local/bin"
|
22
|
-
|
23
|
+
BIN_PATH = ENV['GHCURL_BIN_PATH'] || "/usr/local/bin"
|
24
|
+
HL = HighLine.new
|
25
|
+
|
23
26
|
class Error < StandardError; end
|
24
27
|
|
25
28
|
|
@@ -44,13 +47,90 @@ module Ghcurl
|
|
44
47
|
end
|
45
48
|
|
46
49
|
|
47
|
-
def
|
50
|
+
def get_filters
|
51
|
+
|
52
|
+
arches = [
|
53
|
+
['amd64', 'x86_64', 'x64'],
|
54
|
+
['386', 'i686'],
|
55
|
+
['arm64', 'aarch64'],
|
56
|
+
['armv6', 'arm'],
|
57
|
+
]
|
58
|
+
|
59
|
+
oses = [
|
60
|
+
['linux'],
|
61
|
+
['mac', 'apple'],
|
62
|
+
['windows']
|
63
|
+
]
|
64
|
+
|
65
|
+
fs = RUBY_PLATFORM.split('-')
|
66
|
+
os = ""
|
67
|
+
arch = ""
|
68
|
+
fs.each do |f|
|
69
|
+
case f
|
70
|
+
when 'linux' then os = 'linux'
|
71
|
+
when 'mac','macOS' then os = 'mac'
|
72
|
+
when 'ucrt', 'mingw', 'windows' then os = 'windows'
|
73
|
+
when 'x86_64' then arch = 'x86_64'
|
74
|
+
when 'x86' then arch = 'x86'
|
75
|
+
when 'amd64' then arch = 'amd64'
|
76
|
+
when 'arm64' then arch = 'arm64'
|
77
|
+
when 'armv6' then arch = 'armv6'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
approval, refuse = [], []
|
82
|
+
# [os, arch].each { approval << _1 unless _1.nil? }
|
83
|
+
|
84
|
+
if os
|
85
|
+
i = oses.each_with_index do |type, index|
|
86
|
+
break index if type.include? os
|
87
|
+
end
|
88
|
+
if !i.nil?
|
89
|
+
tmp = oses.dup
|
90
|
+
tmp.delete_at(i)
|
91
|
+
refuse.concat tmp.flatten
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
if arch
|
97
|
+
i = arches.each_with_index do |type, index|
|
98
|
+
break index if type.include? arch
|
99
|
+
end
|
100
|
+
if !i.nil?
|
101
|
+
tmp = arches.dup
|
102
|
+
tmp.delete_at(i)
|
103
|
+
refuse.concat tmp.flatten
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# Debug
|
108
|
+
# puts "=> Approval and refuse"
|
109
|
+
# p [os, arch]
|
110
|
+
# p refuse
|
111
|
+
|
112
|
+
# Now we only refuse others
|
113
|
+
return refuse
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
def download(repo, regexp, version: nil)
|
48
119
|
|
49
120
|
if repo =~ /^https:\/\/github.com/
|
50
121
|
require 'uri'
|
51
122
|
uri = URI(repo)
|
52
123
|
# index 1, take 2
|
53
124
|
repo = uri.path.split('/')[1,2].join('/')
|
125
|
+
elsif !repo.include?('/')
|
126
|
+
got_repo = DEFAULT_WARES[repo.to_sym]
|
127
|
+
if not got_repo
|
128
|
+
user = HL.ask "Who developed the awesome '#{repo}' ? "
|
129
|
+
repo = user + '/' + repo
|
130
|
+
else
|
131
|
+
repo = got_repo
|
132
|
+
log "Use the popular repo #{repo}"
|
133
|
+
end
|
54
134
|
end
|
55
135
|
|
56
136
|
log "checking..."
|
@@ -68,16 +148,45 @@ module Ghcurl
|
|
68
148
|
The search result is empty, check the args:
|
69
149
|
repo: #{repo}
|
70
150
|
version: #{version ? version:'nil'}
|
71
|
-
|
151
|
+
|
72
152
|
EOE
|
73
153
|
puts
|
74
154
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
155
|
+
|
156
|
+
|
157
|
+
links = links.map { _1['href'] }
|
158
|
+
|
159
|
+
|
160
|
+
if regexp
|
161
|
+
filtered = links.select do
|
162
|
+
_1 =~ /#{regexp}/
|
163
|
+
end
|
164
|
+
else
|
165
|
+
refuse = get_filters()
|
166
|
+
filtered = links.select do |l|
|
167
|
+
refuse.all? do |f|
|
168
|
+
l !~ /#{f}/
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
if filtered.size == 1
|
175
|
+
link = filtered[0].split('/').last
|
176
|
+
else
|
177
|
+
if filtered.size == 0
|
178
|
+
links_for_user = links.map { _1.split('/').last }
|
179
|
+
else
|
180
|
+
links_for_user = filtered.map { _1.split('/').last }
|
181
|
+
end
|
182
|
+
link = HL.choose do |menu|
|
183
|
+
menu.index_color = :rgb_77bbff
|
184
|
+
menu.prompt = "Which one do you want to download? "
|
185
|
+
menu.choices( *links_for_user )
|
186
|
+
end
|
78
187
|
end
|
79
188
|
|
80
|
-
url = "https://github.com" + link
|
189
|
+
url = "https://github.com" + links[0].split('/')[0..-2].join('/') + '/' + link
|
81
190
|
|
82
191
|
log "Downloading #{url}"
|
83
192
|
|
@@ -87,12 +196,29 @@ module Ghcurl
|
|
87
196
|
|
88
197
|
end
|
89
198
|
|
199
|
+
|
90
200
|
def install(ware, place: BIN_PATH)
|
201
|
+
|
202
|
+
ware_name = ''
|
203
|
+
if ware.include?('/')
|
204
|
+
ware_name = ware.split('/').last
|
205
|
+
else
|
206
|
+
ware_name = ware
|
207
|
+
end
|
208
|
+
|
209
|
+
if (! $downloaded.include?(ware_name)) and (!$downloaded.end_with?('.deb')) and (!$downloaded.end_with?('.rpm'))
|
210
|
+
log "Do you want to rename or install it to a different path?"
|
211
|
+
re = HL.ask "Input path or name, or just enter to say no."
|
212
|
+
if !re.empty?
|
213
|
+
place = re
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
91
217
|
case RUBY_PLATFORM
|
92
218
|
when /ucrt/i, /mingw/i
|
93
|
-
install_on_windows(
|
219
|
+
install_on_windows($downloaded, place)
|
94
220
|
else
|
95
|
-
install_on_nix(
|
221
|
+
install_on_nix($downloaded, place)
|
96
222
|
end
|
97
223
|
log "Install finish!"
|
98
224
|
end
|
@@ -136,6 +262,7 @@ module Ghcurl
|
|
136
262
|
|
137
263
|
|
138
264
|
def install_on_windows
|
265
|
+
log "Sorry, not implemented yet!"
|
139
266
|
end
|
140
267
|
|
141
268
|
|
@@ -152,21 +279,23 @@ module Ghcurl
|
|
152
279
|
|
153
280
|
def help
|
154
281
|
puts <<~EOC
|
155
|
-
ghcurl (v#{VERSION}): Download files
|
282
|
+
ghcurl (v#{VERSION}): Download files and install from Github releases
|
283
|
+
|
284
|
+
Default install to env 'GHCURL_BIN_PATH' or /usr/local/bin
|
156
285
|
|
157
286
|
usage:
|
158
|
-
ghcurl
|
159
|
-
ghcurl
|
160
|
-
ghcurl
|
161
|
-
ghcurl
|
162
|
-
ghcurl
|
163
|
-
ghcurl
|
164
|
-
ghcurl -
|
165
|
-
ghcurl -h => Print this help
|
287
|
+
ghcurl [user]/repo [regexp] => Search latest version with regexp to download
|
288
|
+
ghcurl repo [re] -v tag => Download a specific tag version
|
289
|
+
ghcurl repo [deb/rpm] => Download and install deb/rpm package
|
290
|
+
ghcurl repo [re] -i [path] => Download and install to path
|
291
|
+
ghcurl repo [re] -i name => Download and install as 'name'
|
292
|
+
ghcurl -l => List downloaded files
|
293
|
+
ghcurl -h => Print this help
|
166
294
|
|
167
295
|
example:
|
296
|
+
ghcurl bat => Search sharkdp/bat the latest
|
297
|
+
ghcurl cli deb -i => Search cli/cli /deb/
|
168
298
|
ghcurl rbspy/rbspy 'x86_64.*linux' -v0.11.1
|
169
|
-
ghcurl cli/cli deb -i
|
170
299
|
|
171
300
|
EOC
|
172
301
|
end
|
@@ -180,53 +309,61 @@ end
|
|
180
309
|
####################
|
181
310
|
extend Ghcurl
|
182
311
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
when nil then help ; exit
|
189
|
-
end
|
190
|
-
|
191
|
-
if ware.nil?
|
192
|
-
log "ghcurl: Download what?"
|
193
|
-
log " use: ghcurl repo file"
|
194
|
-
exit
|
195
|
-
end
|
196
|
-
|
312
|
+
CO = CliSwitch::Option
|
313
|
+
op_config = [] << CO.new(name: 'install', short: '-i', arg_required: 'optional') <<
|
314
|
+
CO.new(name: 'version', short: '-v', arg_required: 'required') <<
|
315
|
+
CO.new(name: 'help', short: '-h', long: '--help', arg_required: 'noarg') <<
|
316
|
+
CO.new(name: 'list', short: '-l', arg_required: 'noarg')
|
197
317
|
|
198
|
-
|
318
|
+
cli = CliSwitch.new(op_config)
|
319
|
+
args, opts = cli.parse(ARGV)
|
199
320
|
|
200
|
-
|
321
|
+
if args.empty? and opts.empty?
|
322
|
+
help
|
323
|
+
exit
|
324
|
+
end
|
201
325
|
|
202
|
-
|
203
|
-
|
204
|
-
download gh_repo, ware, version: ARGV.shift
|
205
|
-
when /-v\d.*/
|
206
|
-
v = arg.split('-v')[1]
|
207
|
-
download gh_repo, ware, version: v
|
326
|
+
if args.size >= 2
|
327
|
+
repo_or_name, regexp = args[0], args[1]
|
208
328
|
else
|
209
|
-
|
210
|
-
next_op = false
|
329
|
+
repo_or_name, regexp = args[0], nil
|
211
330
|
end
|
212
331
|
|
213
332
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
333
|
+
version = nil
|
334
|
+
need_install = false
|
335
|
+
install_to = nil
|
336
|
+
|
337
|
+
opts.each do
|
338
|
+
case _1.name
|
339
|
+
when 'help'
|
340
|
+
help
|
341
|
+
exit
|
342
|
+
when 'list'
|
343
|
+
list_wares
|
344
|
+
exit
|
345
|
+
when 'version'
|
346
|
+
version = _1.next_arg
|
347
|
+
when 'install'
|
348
|
+
need_install = true
|
349
|
+
install_to = _1.next_arg
|
350
|
+
end
|
218
351
|
end
|
219
352
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
353
|
+
# Debug
|
354
|
+
# p repo_or_name
|
355
|
+
# p regexp
|
356
|
+
# p need_install
|
357
|
+
# p install_to
|
358
|
+
|
359
|
+
begin
|
360
|
+
download(repo_or_name, regexp, version: version)
|
361
|
+
if need_install
|
362
|
+
if install_to
|
363
|
+
install(repo_or_name, place: install_to)
|
226
364
|
else
|
227
|
-
install(
|
365
|
+
install(repo_or_name)
|
228
366
|
end
|
229
|
-
|
230
|
-
|
231
|
-
install($downloaded, place: place)
|
367
|
+
end
|
368
|
+
rescue Interrupt
|
232
369
|
end
|
data/lib/ghcurl.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# ------------------------------------------------------
|
2
|
+
# File : ghcurl.rb
|
3
|
+
# Authors : ccmywish <ccmywish@qq.com>
|
4
|
+
# Created on : <2022-04-12>
|
5
|
+
# Last modified : <2022-04-14>
|
6
|
+
#
|
7
|
+
# ghcurl:
|
8
|
+
#
|
9
|
+
# This is the lib file.
|
10
|
+
#
|
11
|
+
# ------------------------------------------------------
|
12
|
+
|
13
|
+
module Ghcurl
|
14
|
+
|
15
|
+
VERSION = "0.5.0"
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
#
|
20
|
+
# We consider from this:
|
21
|
+
#
|
22
|
+
# https://github.com/ibraheemdev/modern-unix
|
23
|
+
#
|
24
|
+
Ghcurl::DEFAULT_WARES = {
|
25
|
+
|
26
|
+
cli: 'cli/cli',
|
27
|
+
|
28
|
+
fd: 'sharkdp/fd',
|
29
|
+
bat: 'sharkdp/bat',
|
30
|
+
hyperfine: 'sharkdp/hyperfine',
|
31
|
+
hexyl: 'sharkdp/hexyl',
|
32
|
+
|
33
|
+
exa: 'ogham/exa',
|
34
|
+
dog: 'ogham/dog',
|
35
|
+
|
36
|
+
lsd: 'Peltoche/lsd',
|
37
|
+
delta: 'dandavison/delta',
|
38
|
+
dust: 'bootandy/dust',
|
39
|
+
duf: 'muesli/duf',
|
40
|
+
broot: 'Canop/broot',
|
41
|
+
|
42
|
+
ripgrep: 'BurntSushi/ripgrep',
|
43
|
+
rg: 'BurntSushi/ripgrep',
|
44
|
+
ag: 'ggreer/the_silver_searcher',
|
45
|
+
|
46
|
+
fzf: 'junegunn/fzf',
|
47
|
+
fzy: 'jhawthorn/fzy',
|
48
|
+
|
49
|
+
mcfly: 'cantino/mcfly',
|
50
|
+
choose: 'theryangeary/choose',
|
51
|
+
jq: 'stedolan/jq',
|
52
|
+
sd: 'chmln/sd',
|
53
|
+
cheat: 'cheat/cheat',
|
54
|
+
bottom: 'ClementTsang/bottom',
|
55
|
+
glances: 'nicolargo/glances',
|
56
|
+
gtop: 'aksakalli/gtop',
|
57
|
+
gping: 'orf/gping',
|
58
|
+
procs: 'dalance/procs',
|
59
|
+
httpie: 'httpie/httpie',
|
60
|
+
curlie: 'rs/curlie',
|
61
|
+
xh: 'ducaale/xh',
|
62
|
+
zoxide: 'ajeetdsouza/zoxide',
|
63
|
+
|
64
|
+
scc: 'boyter/scc'
|
65
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ghcurl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: highline
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: cliswitch
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.2'
|
27
55
|
description: Download files (and install) from Github releases.
|
28
56
|
email:
|
29
57
|
- ccmywish@qq.com
|
@@ -37,6 +65,7 @@ files:
|
|
37
65
|
- README.md
|
38
66
|
- Rakefile
|
39
67
|
- bin/ghcurl
|
68
|
+
- lib/ghcurl.rb
|
40
69
|
homepage: https://github.com/ccmywish/ghcurl
|
41
70
|
licenses:
|
42
71
|
- MIT
|