utils 0.96.0 → 0.97.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/Rakefile +1 -1
- data/bin/charpick +123 -0
- data/lib/utils/version.rb +1 -1
- data/utils.gemspec +7 -7
- metadata +8 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '088f06f0b7afc673dfe77ddc10735e335adc01e5a2123162fc518be1f16d233e'
|
|
4
|
+
data.tar.gz: 9a4b0425541b6f7ef5174a4fa31fb6f582014de7e5f5f158d69b2dedc169fd7c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9a66320d7a7b3cd863660fb3e4f2944631c0340ffb3e16f1c35afc6b00505f124956ba23bfb7f2b4d7b46563074b0201a039dbfc52aef5ba0864fab85b1ccdb2
|
|
7
|
+
data.tar.gz: d193b6d96ad83d2f8846746a69f72318d817d3a8560edddb551d35a022b5267be23fa8c997b626a738dae9a6c7d17f7d2a4be39b0852fb4e762923e3b8284850
|
data/Rakefile
CHANGED
|
@@ -31,7 +31,7 @@ GemHadar do
|
|
|
31
31
|
dependency 'mize', '~> 0.6'
|
|
32
32
|
dependency 'amatch', '~> 0.6'
|
|
33
33
|
dependency 'kramdown-ansi', '>= 0.4'
|
|
34
|
-
dependency 'search_ui', '>= 0.0
|
|
34
|
+
dependency 'search_ui', '>= 0.2.0'
|
|
35
35
|
dependency 'all_images', '>= 0.12'
|
|
36
36
|
dependency 'starscope'
|
|
37
37
|
dependency 'webrick'
|
data/bin/charpick
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
#
|
|
3
|
+
# charpick — search Unicode characters by name and copy the glyph to the
|
|
4
|
+
# system clipboard.
|
|
5
|
+
#
|
|
6
|
+
# The data source is UnicodeData.txt (UCD), cached under
|
|
7
|
+
# $XDG_CACHE_HOME/charpick/UnicodeData.txt and downloaded on first use.
|
|
8
|
+
#
|
|
9
|
+
# Usage:
|
|
10
|
+
# charpick # interactive search
|
|
11
|
+
# charpick rightarrow # pre-fill the search field
|
|
12
|
+
#
|
|
13
|
+
# Requires the search_ui (>= 0.2), amatch, and tins gems.
|
|
14
|
+
|
|
15
|
+
require 'utils'
|
|
16
|
+
require 'net/http'
|
|
17
|
+
require 'uri'
|
|
18
|
+
require 'search_ui'
|
|
19
|
+
require 'tins/xt'
|
|
20
|
+
require 'amatch'
|
|
21
|
+
|
|
22
|
+
module Charpick
|
|
23
|
+
# A single Unicode character with its codepoint and lowercased name.
|
|
24
|
+
Entry = Data.define(:codepoint, :char, :name)
|
|
25
|
+
|
|
26
|
+
DATA_URL = 'https://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt'
|
|
27
|
+
CACHE_DIR = Utils::XDG::XDG_CACHE_HOME.sub_dir_path('charpick')
|
|
28
|
+
DATA_FILE = CACHE_DIR + 'UnicodeData.txt'
|
|
29
|
+
|
|
30
|
+
# Loads the character database, downloading it on first run.
|
|
31
|
+
#
|
|
32
|
+
# @return [ Array<Charpick::Entry> ] all named Unicode characters
|
|
33
|
+
def self.data
|
|
34
|
+
download unless File.exist?(DATA_FILE)
|
|
35
|
+
File.readlines(DATA_FILE, chomp: true).filter_map do |line|
|
|
36
|
+
codepoint, name, = line.split(';')
|
|
37
|
+
next unless name
|
|
38
|
+
code = Integer(codepoint, 16)
|
|
39
|
+
Entry.new(code, [code].pack(?U), name.downcase.tr(' ', '-'))
|
|
40
|
+
rescue
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Downloads the UCD character database into the cache directory.
|
|
45
|
+
#
|
|
46
|
+
# @return [ void ]
|
|
47
|
+
def self.download
|
|
48
|
+
uri = URI(DATA_URL)
|
|
49
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
|
50
|
+
File.write(DATA_FILE, http.get(uri.request_uri).body)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Max number of result rows to render (fits the terminal height).
|
|
55
|
+
#
|
|
56
|
+
# @return [ Integer ]
|
|
57
|
+
def self.limit
|
|
58
|
+
Tins::Terminal.lines - 1
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Finds the first available clipboard command.
|
|
62
|
+
#
|
|
63
|
+
# @return [ [ String, Array<String> ], nil ] the command path with its
|
|
64
|
+
# arguments, or nil if no clipboard tool is installed
|
|
65
|
+
def self.clipboard
|
|
66
|
+
commands = {
|
|
67
|
+
'pbcopy' => [],
|
|
68
|
+
'wl-copy' => [],
|
|
69
|
+
'xclip' => %w[ -selection clipboard ],
|
|
70
|
+
'xsel' => %w[ --clipboard --input ],
|
|
71
|
+
}
|
|
72
|
+
commands.each do |name, args|
|
|
73
|
+
path = `which #{name}`.full?(:chomp) or next
|
|
74
|
+
return [ path, args ]
|
|
75
|
+
end
|
|
76
|
+
nil
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Copies a string to the system clipboard.
|
|
80
|
+
#
|
|
81
|
+
# @param char [ String ] the string to copy
|
|
82
|
+
# @return [ Boolean ] true on success, false if no clipboard tool ran
|
|
83
|
+
def self.copy(char)
|
|
84
|
+
cmd = clipboard
|
|
85
|
+
return false unless cmd
|
|
86
|
+
IO.popen([ cmd[0], *cmd[1] ], 'w') { |io| io.write(char) }
|
|
87
|
+
true
|
|
88
|
+
rescue StandardError
|
|
89
|
+
false
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
entries = Charpick.data
|
|
94
|
+
limit = Charpick.limit
|
|
95
|
+
|
|
96
|
+
state = SearchUI::Search::State.new(ARGV.join(' '), 0)
|
|
97
|
+
selected = SearchUI::Search.new(
|
|
98
|
+
match: -> answer {
|
|
99
|
+
return [] if answer.empty?
|
|
100
|
+
matcher = Amatch::PairDistance.new(answer.downcase)
|
|
101
|
+
entries.map { |entry| [ entry, matcher.similar(entry.name) ] }
|
|
102
|
+
.select { |_, score| score > 0 }
|
|
103
|
+
.sort_by { |_, score| -score }
|
|
104
|
+
.first(limit)
|
|
105
|
+
.map(&:first)
|
|
106
|
+
},
|
|
107
|
+
query: -> _answer, matches, selector {
|
|
108
|
+
return 'Type to search names (e.g. "rightarrow").' if matches.empty?
|
|
109
|
+
matches.each_with_index.map do |entry, i|
|
|
110
|
+
line = "%s U+%04X %s" % [ entry.char, entry.codepoint, entry.name ]
|
|
111
|
+
i == selector ? "→ " + SearchUI::Search.on_blue(line) : " " + line
|
|
112
|
+
end * ?\n
|
|
113
|
+
},
|
|
114
|
+
found: -> _answer, matches, selector { matches[selector] },
|
|
115
|
+
state:
|
|
116
|
+
).start
|
|
117
|
+
|
|
118
|
+
exit 1 if selected.nil?
|
|
119
|
+
|
|
120
|
+
copied = Charpick.copy(selected.char)
|
|
121
|
+
puts format('U+%04X %s %s — %s', selected.codepoint, selected.char,
|
|
122
|
+
selected.name, copied ? 'copied to clipboard ✓' : 'printed (no clipboard)')
|
|
123
|
+
puts format('ruby escape: "\\u%04x"', selected.codepoint)
|
data/lib/utils/version.rb
CHANGED
data/utils.gemspec
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
# stub: utils 0.
|
|
2
|
+
# stub: utils 0.97.0 ruby lib
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |s|
|
|
5
5
|
s.name = "utils".freeze
|
|
6
|
-
s.version = "0.
|
|
6
|
+
s.version = "0.97.0".freeze
|
|
7
7
|
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
|
9
9
|
s.require_paths = ["lib".freeze]
|
|
@@ -11,19 +11,19 @@ Gem::Specification.new do |s|
|
|
|
11
11
|
s.date = "1980-01-02"
|
|
12
12
|
s.description = "This ruby gem provides some useful command line utilities".freeze
|
|
13
13
|
s.email = "flori@ping.de".freeze
|
|
14
|
-
s.executables = ["ascii7".freeze, "blameline".freeze, "changes".freeze, "classify".freeze, "code_comment".freeze, "code_indexer".freeze, "commit_message".freeze, "discover".freeze, "edit".freeze, "edit_wait".freeze, "enum".freeze, "git-empty".freeze, "git-versions".freeze, "irb_client".freeze, "json_check".freeze, "long_lines".freeze, "myex".freeze, "on_change".freeze, "path".freeze, "print_method".freeze, "probe".freeze, "rainbow".freeze, "rd2md".freeze, "search".freeze, "sedit".freeze, "serve".freeze, "ssh-tunnel".freeze, "strip_spaces".freeze, "sync_dir".freeze, "untest".freeze, "utils-utilsrc".freeze, "vcf2alias".freeze, "yaml_check".freeze]
|
|
14
|
+
s.executables = ["ascii7".freeze, "blameline".freeze, "changes".freeze, "charpick".freeze, "classify".freeze, "code_comment".freeze, "code_indexer".freeze, "commit_message".freeze, "discover".freeze, "edit".freeze, "edit_wait".freeze, "enum".freeze, "git-empty".freeze, "git-versions".freeze, "irb_client".freeze, "json_check".freeze, "long_lines".freeze, "myex".freeze, "on_change".freeze, "path".freeze, "print_method".freeze, "probe".freeze, "rainbow".freeze, "rd2md".freeze, "search".freeze, "sedit".freeze, "serve".freeze, "ssh-tunnel".freeze, "strip_spaces".freeze, "sync_dir".freeze, "untest".freeze, "utils-utilsrc".freeze, "vcf2alias".freeze, "yaml_check".freeze]
|
|
15
15
|
s.extra_rdoc_files = ["README.md".freeze, "lib/utils.rb".freeze, "lib/utils/config_file.rb".freeze, "lib/utils/config_file/block_config.rb".freeze, "lib/utils/editor.rb".freeze, "lib/utils/finder.rb".freeze, "lib/utils/finder/files.rb".freeze, "lib/utils/grepper.rb".freeze, "lib/utils/irb.rb".freeze, "lib/utils/irb/irb_server.rb".freeze, "lib/utils/irb/regexp.rb".freeze, "lib/utils/irb/shell.rb".freeze, "lib/utils/irb/shell/wrappers.rb".freeze, "lib/utils/irb/string.rb".freeze, "lib/utils/line_blamer.rb".freeze, "lib/utils/line_formatter.rb".freeze, "lib/utils/md5.rb".freeze, "lib/utils/patterns.rb".freeze, "lib/utils/probe.rb".freeze, "lib/utils/probe/probe_client.rb".freeze, "lib/utils/probe/probe_server.rb".freeze, "lib/utils/probe/process_job.rb".freeze, "lib/utils/probe/server_handling.rb".freeze, "lib/utils/ssh_tunnel_specification.rb".freeze, "lib/utils/version.rb".freeze, "lib/utils/xdg.rb".freeze, "lib/utils/xt/source_location_extension.rb".freeze]
|
|
16
|
-
s.files = [".contexts/lib.rb".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "bin/ascii7".freeze, "bin/blameline".freeze, "bin/changes".freeze, "bin/classify".freeze, "bin/code_comment".freeze, "bin/code_indexer".freeze, "bin/commit_message".freeze, "bin/discover".freeze, "bin/edit".freeze, "bin/edit_wait".freeze, "bin/enum".freeze, "bin/git-empty".freeze, "bin/git-versions".freeze, "bin/irb_client".freeze, "bin/json_check".freeze, "bin/long_lines".freeze, "bin/myex".freeze, "bin/on_change".freeze, "bin/path".freeze, "bin/print_method".freeze, "bin/probe".freeze, "bin/rainbow".freeze, "bin/rd2md".freeze, "bin/search".freeze, "bin/sedit".freeze, "bin/serve".freeze, "bin/ssh-tunnel".freeze, "bin/strip_spaces".freeze, "bin/sync_dir".freeze, "bin/untest".freeze, "bin/utils-utilsrc".freeze, "bin/vcf2alias".freeze, "bin/yaml_check".freeze, "lib/utils.rb".freeze, "lib/utils/config_file.rb".freeze, "lib/utils/config_file/block_config.rb".freeze, "lib/utils/editor.rb".freeze, "lib/utils/finder.rb".freeze, "lib/utils/finder/files.rb".freeze, "lib/utils/grepper.rb".freeze, "lib/utils/irb.rb".freeze, "lib/utils/irb/irb_server.rb".freeze, "lib/utils/irb/regexp.rb".freeze, "lib/utils/irb/shell.rb".freeze, "lib/utils/irb/shell/wrappers.rb".freeze, "lib/utils/irb/string.rb".freeze, "lib/utils/line_blamer.rb".freeze, "lib/utils/line_formatter.rb".freeze, "lib/utils/md5.rb".freeze, "lib/utils/patterns.rb".freeze, "lib/utils/probe.rb".freeze, "lib/utils/probe/probe_client.rb".freeze, "lib/utils/probe/probe_server.rb".freeze, "lib/utils/probe/process_job.rb".freeze, "lib/utils/probe/server_handling.rb".freeze, "lib/utils/ssh_tunnel_specification.rb".freeze, "lib/utils/version.rb".freeze, "lib/utils/xdg.rb".freeze, "lib/utils/xt/source_location_extension.rb".freeze, "tests/test_helper.rb".freeze, "tests/utils_test.rb".freeze, "utils.gemspec".freeze]
|
|
16
|
+
s.files = [".contexts/lib.rb".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "bin/ascii7".freeze, "bin/blameline".freeze, "bin/changes".freeze, "bin/charpick".freeze, "bin/classify".freeze, "bin/code_comment".freeze, "bin/code_indexer".freeze, "bin/commit_message".freeze, "bin/discover".freeze, "bin/edit".freeze, "bin/edit_wait".freeze, "bin/enum".freeze, "bin/git-empty".freeze, "bin/git-versions".freeze, "bin/irb_client".freeze, "bin/json_check".freeze, "bin/long_lines".freeze, "bin/myex".freeze, "bin/on_change".freeze, "bin/path".freeze, "bin/print_method".freeze, "bin/probe".freeze, "bin/rainbow".freeze, "bin/rd2md".freeze, "bin/search".freeze, "bin/sedit".freeze, "bin/serve".freeze, "bin/ssh-tunnel".freeze, "bin/strip_spaces".freeze, "bin/sync_dir".freeze, "bin/untest".freeze, "bin/utils-utilsrc".freeze, "bin/vcf2alias".freeze, "bin/yaml_check".freeze, "lib/utils.rb".freeze, "lib/utils/config_file.rb".freeze, "lib/utils/config_file/block_config.rb".freeze, "lib/utils/editor.rb".freeze, "lib/utils/finder.rb".freeze, "lib/utils/finder/files.rb".freeze, "lib/utils/grepper.rb".freeze, "lib/utils/irb.rb".freeze, "lib/utils/irb/irb_server.rb".freeze, "lib/utils/irb/regexp.rb".freeze, "lib/utils/irb/shell.rb".freeze, "lib/utils/irb/shell/wrappers.rb".freeze, "lib/utils/irb/string.rb".freeze, "lib/utils/line_blamer.rb".freeze, "lib/utils/line_formatter.rb".freeze, "lib/utils/md5.rb".freeze, "lib/utils/patterns.rb".freeze, "lib/utils/probe.rb".freeze, "lib/utils/probe/probe_client.rb".freeze, "lib/utils/probe/probe_server.rb".freeze, "lib/utils/probe/process_job.rb".freeze, "lib/utils/probe/server_handling.rb".freeze, "lib/utils/ssh_tunnel_specification.rb".freeze, "lib/utils/version.rb".freeze, "lib/utils/xdg.rb".freeze, "lib/utils/xt/source_location_extension.rb".freeze, "tests/test_helper.rb".freeze, "tests/utils_test.rb".freeze, "utils.gemspec".freeze]
|
|
17
17
|
s.homepage = "http://github.com/flori/utils".freeze
|
|
18
18
|
s.licenses = ["GPL-2.0".freeze]
|
|
19
19
|
s.rdoc_options = ["--title".freeze, "Utils - Some useful command line utilities".freeze, "--main".freeze, "README.md".freeze]
|
|
20
|
-
s.rubygems_version = "4.0.
|
|
20
|
+
s.rubygems_version = "4.0.17".freeze
|
|
21
21
|
s.summary = "Some useful command line utilities".freeze
|
|
22
22
|
s.test_files = ["tests/test_helper.rb".freeze, "tests/utils_test.rb".freeze]
|
|
23
23
|
|
|
24
24
|
s.specification_version = 4
|
|
25
25
|
|
|
26
|
-
s.add_development_dependency(%q<gem_hadar>.freeze, [">= 2.
|
|
26
|
+
s.add_development_dependency(%q<gem_hadar>.freeze, [">= 2.18.0".freeze])
|
|
27
27
|
s.add_development_dependency(%q<test-unit>.freeze, [">= 0".freeze])
|
|
28
28
|
s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.51".freeze])
|
|
29
29
|
s.add_runtime_dependency(%q<term-ansicolor>.freeze, ["~> 1.11".freeze])
|
|
@@ -36,7 +36,7 @@ Gem::Specification.new do |s|
|
|
|
36
36
|
s.add_runtime_dependency(%q<mize>.freeze, ["~> 0.6".freeze])
|
|
37
37
|
s.add_runtime_dependency(%q<amatch>.freeze, ["~> 0.6".freeze])
|
|
38
38
|
s.add_runtime_dependency(%q<kramdown-ansi>.freeze, [">= 0.4".freeze])
|
|
39
|
-
s.add_runtime_dependency(%q<search_ui>.freeze, [">= 0.0
|
|
39
|
+
s.add_runtime_dependency(%q<search_ui>.freeze, [">= 0.2.0".freeze])
|
|
40
40
|
s.add_runtime_dependency(%q<all_images>.freeze, [">= 0.12".freeze])
|
|
41
41
|
s.add_runtime_dependency(%q<starscope>.freeze, [">= 0".freeze])
|
|
42
42
|
s.add_runtime_dependency(%q<webrick>.freeze, [">= 0".freeze])
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: utils
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.97.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Florian Frank
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 2.
|
|
18
|
+
version: 2.18.0
|
|
19
19
|
type: :development
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 2.
|
|
25
|
+
version: 2.18.0
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: test-unit
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -197,14 +197,14 @@ dependencies:
|
|
|
197
197
|
requirements:
|
|
198
198
|
- - ">="
|
|
199
199
|
- !ruby/object:Gem::Version
|
|
200
|
-
version: 0.0
|
|
200
|
+
version: 0.2.0
|
|
201
201
|
type: :runtime
|
|
202
202
|
prerelease: false
|
|
203
203
|
version_requirements: !ruby/object:Gem::Requirement
|
|
204
204
|
requirements:
|
|
205
205
|
- - ">="
|
|
206
206
|
- !ruby/object:Gem::Version
|
|
207
|
-
version: 0.0
|
|
207
|
+
version: 0.2.0
|
|
208
208
|
- !ruby/object:Gem::Dependency
|
|
209
209
|
name: all_images
|
|
210
210
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -281,6 +281,7 @@ executables:
|
|
|
281
281
|
- ascii7
|
|
282
282
|
- blameline
|
|
283
283
|
- changes
|
|
284
|
+
- charpick
|
|
284
285
|
- classify
|
|
285
286
|
- code_comment
|
|
286
287
|
- code_indexer
|
|
@@ -349,6 +350,7 @@ files:
|
|
|
349
350
|
- bin/ascii7
|
|
350
351
|
- bin/blameline
|
|
351
352
|
- bin/changes
|
|
353
|
+
- bin/charpick
|
|
352
354
|
- bin/classify
|
|
353
355
|
- bin/code_comment
|
|
354
356
|
- bin/code_indexer
|
|
@@ -430,7 +432,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
430
432
|
- !ruby/object:Gem::Version
|
|
431
433
|
version: '0'
|
|
432
434
|
requirements: []
|
|
433
|
-
rubygems_version: 4.0.
|
|
435
|
+
rubygems_version: 4.0.17
|
|
434
436
|
specification_version: 4
|
|
435
437
|
summary: Some useful command line utilities
|
|
436
438
|
test_files:
|