utils 0.6.4 → 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/.gitignore +1 -0
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/bin/blameline +2 -2
- data/bin/classify +48 -12
- data/bin/dialog-pick +11 -0
- data/bin/discover +2 -5
- data/bin/edit +1 -1
- data/bin/probe +1 -1
- data/bin/rssr +37 -0
- data/bin/search +3 -2
- data/bin/serve +24 -0
- data/bin/ssh-tunnel +1 -1
- data/bin/strip_spaces +1 -1
- data/bin/utils-utilsrc +1 -1
- data/lib/utils.rb +1 -2
- data/lib/utils/{config/config_file.rb → config_file.rb} +19 -4
- data/lib/utils/editor.rb +1 -1
- data/lib/utils/finder.rb +18 -19
- data/lib/utils/grepper.rb +20 -3
- data/lib/utils/line_blamer.rb +1 -1
- data/lib/utils/patterns.rb +3 -1
- data/lib/utils/version.rb +1 -1
- data/utils.gemspec +9 -9
- metadata +12 -18
- data/bin/utils-install-config +0 -10
- data/lib/utils/config.rb +0 -23
- data/lib/utils/config/gdb/asm +0 -179
- data/lib/utils/config/gdb/ruby +0 -514
- data/lib/utils/config/gdbinit +0 -8
- data/lib/utils/config/irbrc +0 -3
- data/lib/utils/config/rdebugrc +0 -2
- data/lib/utils/config/rvmrc +0 -5
- data/lib/utils/config/screenrc +0 -143
- data/lib/utils/config/utilsrc +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd2e201421219d45b45d2fe83a850971c3b1f311
|
4
|
+
data.tar.gz: 5ba5419654b33453698c6c249749b132081b4555
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6553dda498be7fd555abacb3cd3ef8df38d7d0e408af0fddc76f856cd21ff93c73972fd1719c1cc68e1ddff346d774162b750c736faf4e4a10d6b7f5f3dfe4df
|
7
|
+
data.tar.gz: aced2f21c40473b7d006abe96be590a4095a86b32a1c62e2cc9b6eb0335a8630e09c545e13ace4941baec8bc5f86114f26f90b5244051826ea307c5a0bf3dd05
|
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -12,7 +12,8 @@ GemHadar do
|
|
12
12
|
bindir 'bin'
|
13
13
|
executables Dir['bin/*'].map(&File.method(:basename))
|
14
14
|
test_dir 'tests'
|
15
|
-
ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc', '.AppleDouble',
|
15
|
+
ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc', '.AppleDouble',
|
16
|
+
'tags', '.bundle', '.DS_Store'
|
16
17
|
readme 'README.md'
|
17
18
|
|
18
19
|
dependency 'tins', '~>1.8'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.0
|
data/bin/blameline
CHANGED
@@ -22,8 +22,8 @@ end
|
|
22
22
|
|
23
23
|
for line in lines
|
24
24
|
blamer = Utils::LineBlamer.for_line(line) or next
|
25
|
-
blame = blamer.perform
|
26
|
-
blame.sub!(/^[0-9a-f]+/) { Term::ANSIColor.yellow($&) }
|
25
|
+
blame = blamer.perform or next
|
26
|
+
blame.sub!(/^[0-9a-f^]+/) { Term::ANSIColor.yellow($&) }
|
27
27
|
blame.sub!(/\(([^)]+)\)/) { "(#{Term::ANSIColor.red($1)})" }
|
28
28
|
puts blame
|
29
29
|
end
|
data/bin/classify
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
require 'utils'
|
3
4
|
require 'tins/go'
|
4
5
|
include Tins::GO
|
5
6
|
require 'tins/xt/string'
|
7
|
+
require 'term/ansicolor'
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
string = ARGV.shift or fail "need a class/filepath/filename"
|
10
|
-
|
11
|
-
def path_shifter(string, separator: ?/, n: 0)
|
9
|
+
def path_shifter(string, separator: ?/, n: nil)
|
12
10
|
n or return string
|
13
11
|
n, path = n.to_i, string.split(separator)
|
14
12
|
if n < 0
|
@@ -21,27 +19,65 @@ end
|
|
21
19
|
|
22
20
|
def underscore(string)
|
23
21
|
string = path_shifter(string, n: $opts['n'], separator: '::')
|
24
|
-
string = string.
|
22
|
+
string = Tins::StringUnderscore.instance_method(:underscore).bind(string).()
|
25
23
|
$opts['s'] and string << '.rb'
|
26
|
-
|
24
|
+
string
|
25
|
+
end
|
26
|
+
|
27
|
+
def parameterize(string, separator)
|
28
|
+
underscore(string).gsub(?/, separator) # quick and dirty
|
27
29
|
end
|
28
30
|
|
29
31
|
def camelize(string)
|
30
32
|
string = path_shifter(string, n: $opts['n'])
|
31
33
|
string = string.gsub(/#{Regexp.quote(File.extname(string))}\Z/, '')
|
32
|
-
|
34
|
+
string.camelize
|
35
|
+
end
|
36
|
+
|
37
|
+
def camelcase?(string)
|
38
|
+
string[0, 1] =~ /[A-Z]/
|
39
|
+
end
|
40
|
+
|
41
|
+
def compute_shift(config, string)
|
42
|
+
string = underscore(string)
|
43
|
+
result = config.classify.shift_path_by_default
|
44
|
+
for prefix in config.classify.shift_path_for_prefix
|
45
|
+
if string.start_with? prefix
|
46
|
+
return prefix.count(?/) + 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
result
|
33
50
|
end
|
34
51
|
|
52
|
+
$opts = go 'bdtsp:n:'
|
53
|
+
|
54
|
+
|
55
|
+
string = ARGV.shift or fail "need a class/filepath/filename"
|
56
|
+
string = Term::ANSIColor.uncolor string
|
57
|
+
|
58
|
+
config = Utils::ConfigFile.new
|
59
|
+
config.configure_from_paths
|
60
|
+
|
61
|
+
$opts['n'] ||= compute_shift(config, string)
|
62
|
+
|
35
63
|
$opts['b'] and $opts['n'] = '-1'
|
36
|
-
case
|
64
|
+
print case
|
37
65
|
when $opts['t']
|
38
|
-
if string
|
39
|
-
|
66
|
+
if camelcase?(string)
|
67
|
+
if separator = $opts['p']
|
68
|
+
parameterize string, separator
|
69
|
+
else
|
70
|
+
underscore string
|
71
|
+
end
|
40
72
|
else
|
41
73
|
camelize string
|
42
74
|
end
|
43
75
|
when $opts['d']
|
44
|
-
|
76
|
+
if separator = $opts['p']
|
77
|
+
parameterize string, separator
|
78
|
+
else
|
79
|
+
underscore string
|
80
|
+
end
|
45
81
|
else
|
46
82
|
camelize string
|
47
83
|
end
|
data/bin/dialog-pick
ADDED
data/bin/discover
CHANGED
@@ -32,10 +32,7 @@ directory and file paths that are searched.
|
|
32
32
|
Options are
|
33
33
|
|
34
34
|
-r interpret PATTERN argument as regex not fuzzy
|
35
|
-
-d discover directories as well
|
36
|
-
-D discover only directories
|
37
35
|
-c disable color output
|
38
|
-
-i use case insensitive matches
|
39
36
|
-e open the matching files with edit command
|
40
37
|
-E pick one file to edit
|
41
38
|
-a CSET use only character set CSET from PATTERN
|
@@ -49,14 +46,14 @@ Version is #{File.basename($0)} #{Utils::VERSION}.
|
|
49
46
|
exit 1
|
50
47
|
end
|
51
48
|
|
52
|
-
args = go 'I:a:
|
49
|
+
args = go 'I:a:rceEbvh'
|
53
50
|
args['h'] and usage
|
54
51
|
pattern = ARGV.shift or usage
|
55
52
|
roots = (ARGV.empty? ? [ Dir.pwd ] : ARGV).map { |f| File.expand_path(f) }
|
56
53
|
|
57
54
|
Term::ANSIColor.coloring = (STDIN.tty? && ENV['TERM'] !~ /dumb/) && !args['c']
|
58
55
|
STDOUT.sync = true
|
59
|
-
config = Utils::
|
56
|
+
config = Utils::ConfigFile.new
|
60
57
|
config.configure_from_paths
|
61
58
|
args['b'] ||= config.discover.binary
|
62
59
|
finder = Finder.new(
|
data/bin/edit
CHANGED
data/bin/probe
CHANGED
data/bin/rssr
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rss'
|
4
|
+
require 'tins'
|
5
|
+
require 'open-uri'
|
6
|
+
require 'term/ansicolor'
|
7
|
+
|
8
|
+
|
9
|
+
class String
|
10
|
+
include Term::ANSIColor
|
11
|
+
|
12
|
+
def wrap(cols: Tins::Terminal.cols)
|
13
|
+
split(?\n).each do |line|
|
14
|
+
line.size > cols and line.gsub!(/(.{1,#{cols}})(\s+|$)/, "\\1\n")
|
15
|
+
line.strip!
|
16
|
+
end * ?\n
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
IO.popen(ENV.fetch('PAGER', `which less`.chomp << ' -r'), 'w') do |pager|
|
21
|
+
url = ARGV.shift
|
22
|
+
open(url) do |rss|
|
23
|
+
feed = RSS::Parser.parse(rss)
|
24
|
+
pager.puts "Feed: #{feed.channel.title}",
|
25
|
+
?– * Tins::Terminal.cols
|
26
|
+
feed.items.sort_by { |item| -item.date.to_f }.each do |item|
|
27
|
+
pager.puts(
|
28
|
+
"Title: #{item.title.bright_blue}",
|
29
|
+
"Link: #{item.link.red}",
|
30
|
+
"Date: #{item.date.strftime('%FT%T%z')}",
|
31
|
+
"",
|
32
|
+
item.description.wrap.chomp.white,
|
33
|
+
?– * Tins::Terminal.cols
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/bin/search
CHANGED
@@ -125,6 +125,7 @@ Options are
|
|
125
125
|
-e open the matching files with edit command
|
126
126
|
-E pick one file to edit
|
127
127
|
-r REPLACE replace the searched match with REPLACE
|
128
|
+
-b
|
128
129
|
-a CSET use only character set CSET from PATTERN
|
129
130
|
-v be verbose
|
130
131
|
-h display this help
|
@@ -134,14 +135,14 @@ Version is #{File.basename($0)} #{Utils::VERSION}.
|
|
134
135
|
exit 1
|
135
136
|
end
|
136
137
|
|
137
|
-
args = go 'r:I:A:B:C:s:S:n:N:a:
|
138
|
+
args = go 'r:I:A:B:C:s:S:n:N:a:RciflLeEvbh'
|
138
139
|
args['h'] and usage
|
139
140
|
pattern = ARGV.shift or usage
|
140
141
|
roots = (ARGV.empty? ? [ Dir.pwd ] : ARGV).map { |f| File.expand_path(f) }
|
141
142
|
|
142
143
|
Term::ANSIColor.coloring = (STDIN.tty? && ENV['TERM'] !~ /dumb/) && !args['c']
|
143
144
|
STDOUT.sync = true
|
144
|
-
config = Utils::
|
145
|
+
config = Utils::ConfigFile.new
|
145
146
|
config.configure_from_paths
|
146
147
|
grepper = Grepper.new(
|
147
148
|
:pattern => pattern,
|
data/bin/serve
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'tins/go'
|
4
|
+
include Tins::GO
|
5
|
+
require 'webrick'
|
6
|
+
|
7
|
+
$opts = go 'p:h'
|
8
|
+
|
9
|
+
if $opts[?h]
|
10
|
+
puts <<USAGE
|
11
|
+
#{File.basename($0)} [OPTIONS] [DIR]
|
12
|
+
USAGE
|
13
|
+
exit
|
14
|
+
end
|
15
|
+
|
16
|
+
port = ($opts[?p] || 8888).to_i
|
17
|
+
s = WEBrick::HTTPServer.new(
|
18
|
+
Port: port,
|
19
|
+
DocumentRoot: ARGV.shift || Dir.pwd
|
20
|
+
)
|
21
|
+
trap('INT') { s.shutdown }
|
22
|
+
puts "You have been served: http://localhost:#{port}/"
|
23
|
+
s.start
|
24
|
+
|
data/bin/ssh-tunnel
CHANGED
data/bin/strip_spaces
CHANGED
data/bin/utils-utilsrc
CHANGED
data/lib/utils.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'tins'
|
2
2
|
require 'tins/xt/string'
|
3
3
|
|
4
|
-
class Utils::
|
4
|
+
class Utils::ConfigFile
|
5
5
|
class << self
|
6
6
|
attr_accessor :config_file_paths
|
7
7
|
end
|
@@ -64,13 +64,15 @@ class Utils::Config::ConfigFile
|
|
64
64
|
|
65
65
|
def to_ruby(depth = 0)
|
66
66
|
result = ''
|
67
|
-
result << ' ' * 2 * depth <<
|
67
|
+
result << ' ' * 2 * depth <<
|
68
|
+
"#{self.class.name[/::([^:]+)\z/, 1].underscore} do\n"
|
68
69
|
for name in self.class.config_settings
|
69
70
|
value = __send__(name)
|
70
71
|
if value.respond_to?(:to_ruby)
|
71
72
|
result << ' ' * 2 * (depth + 1) << value.to_ruby(depth + 1)
|
72
73
|
else
|
73
|
-
result << ' ' * 2 * (depth + 1) <<
|
74
|
+
result << ' ' * 2 * (depth + 1) <<
|
75
|
+
"#{name} #{Array(value).map(&:inspect) * ', '}\n"
|
74
76
|
end
|
75
77
|
end
|
76
78
|
result << ' ' * 2 * depth << "end\n"
|
@@ -244,9 +246,22 @@ class Utils::Config::ConfigFile
|
|
244
246
|
@edit ||= Edit.new
|
245
247
|
end
|
246
248
|
|
249
|
+
class Classify < BlockConfig
|
250
|
+
config :shift_path_by_default, 0
|
251
|
+
|
252
|
+
config :shift_path_for_prefix, []
|
253
|
+
end
|
254
|
+
|
255
|
+
def classify(&block)
|
256
|
+
if block
|
257
|
+
@classify = Classify.new(&block)
|
258
|
+
end
|
259
|
+
@classify ||= Classify.new
|
260
|
+
end
|
261
|
+
|
247
262
|
def to_ruby
|
248
263
|
result = "# vim: set ft=ruby:\n"
|
249
|
-
for bc in %w[search discover strip_spaces probe ssh_tunnel]
|
264
|
+
for bc in %w[search discover strip_spaces probe ssh_tunnel edit classify]
|
250
265
|
result << "\n" << __send__(bc).to_ruby
|
251
266
|
end
|
252
267
|
result
|
data/lib/utils/editor.rb
CHANGED
@@ -9,7 +9,7 @@ module Utils
|
|
9
9
|
self.wait = false
|
10
10
|
self.pause_duration = 1
|
11
11
|
self.servername = derive_server_name
|
12
|
-
config = Utils::
|
12
|
+
config = Utils::ConfigFile.new
|
13
13
|
config.configure_from_paths
|
14
14
|
self.config = config.edit
|
15
15
|
yield self if block_given?
|
data/lib/utils/finder.rb
CHANGED
@@ -11,19 +11,17 @@ class Utils::Finder
|
|
11
11
|
include Term::ANSIColor
|
12
12
|
|
13
13
|
def initialize(opts = {})
|
14
|
-
@args
|
15
|
-
@roots
|
16
|
-
@config = opts[:config] || Utils::
|
14
|
+
@args = opts[:args] || {}
|
15
|
+
@roots = discover_roots(opts[:roots])
|
16
|
+
@config = opts[:config] || Utils::ConfigFile.new
|
17
17
|
pattern_opts = opts.subhash(:pattern) | {
|
18
18
|
:cset => @args['a'],
|
19
|
-
:icase => @args
|
19
|
+
:icase => @args.fetch('i', true),
|
20
20
|
}
|
21
21
|
@binary = @args['b']
|
22
22
|
@pattern = @args['r'] ?
|
23
23
|
RegexpPattern.new(pattern_opts) :
|
24
24
|
FuzzyPattern.new(pattern_opts)
|
25
|
-
@directory = @args['d']
|
26
|
-
@only_directory = @args['D']
|
27
25
|
@paths = []
|
28
26
|
end
|
29
27
|
|
@@ -38,13 +36,7 @@ class Utils::Finder
|
|
38
36
|
def attempt_match?(path)
|
39
37
|
stat = path.stat
|
40
38
|
stat.symlink? and stat = path.lstat
|
41
|
-
|
42
|
-
stat.directory?
|
43
|
-
elsif @directory
|
44
|
-
stat.directory? || ascii_file?(stat, path)
|
45
|
-
else
|
46
|
-
ascii_file?(stat, path)
|
47
|
-
end
|
39
|
+
stat.directory? || ascii_file?(stat, path)
|
48
40
|
rescue SystemCallError => e
|
49
41
|
warn "Caught #{e.class}: #{e}"
|
50
42
|
nil
|
@@ -73,7 +65,7 @@ class Utils::Finder
|
|
73
65
|
if do_match = attempt_match?(path) and @args['v']
|
74
66
|
warn "Attempt match of #{path.inspect}"
|
75
67
|
end
|
76
|
-
if do_match and match = @pattern.match(
|
68
|
+
if do_match and match = @pattern.match(path)
|
77
69
|
if FuzzyPattern === @pattern
|
78
70
|
current = 0
|
79
71
|
marked_file = ''
|
@@ -81,8 +73,8 @@ class Utils::Finder
|
|
81
73
|
for i in 1...(match.size)
|
82
74
|
match[i] or next
|
83
75
|
b = match.begin(i)
|
84
|
-
marked_file <<
|
85
|
-
marked_file << red(
|
76
|
+
marked_file << path[current...b]
|
77
|
+
marked_file << red(path[b, 1])
|
86
78
|
score += (b - e)
|
87
79
|
e = match.end(i)
|
88
80
|
current = b + 1
|
@@ -90,9 +82,9 @@ class Utils::Finder
|
|
90
82
|
marked_file << match.post_match
|
91
83
|
[ score, file.size, path, File.join(dir, marked_file) ]
|
92
84
|
else
|
93
|
-
marked_file =
|
94
|
-
red(
|
95
|
-
|
85
|
+
marked_file = path[0...match.begin(0)] <<
|
86
|
+
red(path[match.begin(0)...match.end(0)]) <<
|
87
|
+
path[match.end(0)..-1]
|
96
88
|
[ 0, file.size, path, File.join(dir, marked_file) ]
|
97
89
|
end
|
98
90
|
end
|
@@ -101,4 +93,11 @@ class Utils::Finder
|
|
101
93
|
@paths, @output = paths.sort.transpose.values_at(-2, -1)
|
102
94
|
self
|
103
95
|
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def discover_roots(roots)
|
100
|
+
roots ||= []
|
101
|
+
roots.inject([]) { |rs, r| rs.concat Dir[r] }
|
102
|
+
end
|
104
103
|
end
|