utils 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd2e201421219d45b45d2fe83a850971c3b1f311
4
- data.tar.gz: 5ba5419654b33453698c6c249749b132081b4555
3
+ metadata.gz: f866a94b2e6d4f176cb526c5ba15e7721f2cdf48
4
+ data.tar.gz: 7e3e202ebb2c42ef0f66fa803cf6f772bf39588c
5
5
  SHA512:
6
- metadata.gz: 6553dda498be7fd555abacb3cd3ef8df38d7d0e408af0fddc76f856cd21ff93c73972fd1719c1cc68e1ddff346d774162b750c736faf4e4a10d6b7f5f3dfe4df
7
- data.tar.gz: aced2f21c40473b7d006abe96be590a4095a86b32a1c62e2cc9b6eb0335a8630e09c545e13ace4941baec8bc5f86114f26f90b5244051826ea307c5a0bf3dd05
6
+ metadata.gz: 625a650bcdda5ed20739478be0b423022e7956582d643c5310c08600505ad451f787830c55b3d2ad67a1966c668277e09740a77a152cf15f0563d89f6e955837
7
+ data.tar.gz: 02e4866d3c84fb13880deff73a8bcb6a531dd7913eddb20ea88d37ae392a869610d2d7e0d11dd967b0f4df49b900c2c449f39a39247d6e79f96f45515a171eb2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.0
1
+ 0.9.0
data/bin/ascii7 ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ map = Hash.new { |h, k| h[k] = k }.merge(
4
+ " " => "Spc",
5
+ "\x7f" => "DEL"
6
+ ).merge(%w[
7
+ NUL SOH STX ETX EOT ENQ ACK BEL BS TAB LF VT FF CR SO SI DLE DC1 DC2
8
+ DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
9
+ ].each_with_index.map { |s, i| [ i.chr, s ] }.to_h)
10
+ prefixes = 0..0b11
11
+ puts ([ '' ] + prefixes.map { |p| '%02b' % p }) * ?\t
12
+ (1 << 5).times do |x|
13
+ puts ([ "%05b" % x ] + prefixes.map { |p| map[((p << 5) | x).chr] }) * ?\t
14
+ end
data/bin/blameline CHANGED
@@ -21,9 +21,5 @@ else
21
21
  end
22
22
 
23
23
  for line in lines
24
- blamer = Utils::LineBlamer.for_line(line) or next
25
- blame = blamer.perform or next
26
- blame.sub!(/^[0-9a-f^]+/) { Term::ANSIColor.yellow($&) }
27
- blame.sub!(/\(([^)]+)\)/) { "(#{Term::ANSIColor.red($1)})" }
28
- puts blame
24
+ Utils::LineBlamer.blame(line).full? { |l| puts l }
29
25
  end
data/bin/brakeman2err CHANGED
@@ -5,8 +5,8 @@ require 'tins/xt'
5
5
  require 'tins/go'
6
6
  include Tins::GO
7
7
 
8
- opt = go 'c'
9
- if opt['c']
8
+ opts = go 'c'
9
+ if opts[?c]
10
10
  brakeman = `bundle exec which brakeman`.full? or fail "cannot find brakeman in path"
11
11
  system *%w'bundle exec brakeman -q -s brakeman_ignore --url-safe-methods brakeman_ignore -o .brakeman.json' or fail "calling brakeman failed"
12
12
  end
data/bin/classify CHANGED
@@ -18,9 +18,9 @@ def path_shifter(string, separator: ?/, n: nil)
18
18
  end
19
19
 
20
20
  def underscore(string)
21
- string = path_shifter(string, n: $opts['n'], separator: '::')
21
+ string = path_shifter(string, n: $opts[?n], separator: '::')
22
22
  string = Tins::StringUnderscore.instance_method(:underscore).bind(string).()
23
- $opts['s'] and string << '.rb'
23
+ $opts[?s] and string << '.rb'
24
24
  string
25
25
  end
26
26
 
@@ -29,7 +29,7 @@ def parameterize(string, separator)
29
29
  end
30
30
 
31
31
  def camelize(string)
32
- string = path_shifter(string, n: $opts['n'])
32
+ string = path_shifter(string, n: $opts[?n])
33
33
  string = string.gsub(/#{Regexp.quote(File.extname(string))}\Z/, '')
34
34
  string.camelize
35
35
  end
@@ -58,13 +58,13 @@ string = Term::ANSIColor.uncolor string
58
58
  config = Utils::ConfigFile.new
59
59
  config.configure_from_paths
60
60
 
61
- $opts['n'] ||= compute_shift(config, string)
61
+ $opts[?n] ||= compute_shift(config, string)
62
62
 
63
- $opts['b'] and $opts['n'] = '-1'
63
+ $opts[?b] and $opts[?n] = '-1'
64
64
  print case
65
- when $opts['t']
65
+ when $opts[?t]
66
66
  if camelcase?(string)
67
- if separator = $opts['p']
67
+ if separator = $opts[?p]
68
68
  parameterize string, separator
69
69
  else
70
70
  underscore string
@@ -72,8 +72,8 @@ when $opts['t']
72
72
  else
73
73
  camelize string
74
74
  end
75
- when $opts['d']
76
- if separator = $opts['p']
75
+ when $opts[?d]
76
+ if separator = $opts[?p]
77
77
  parameterize string, separator
78
78
  else
79
79
  underscore string
data/bin/discover CHANGED
@@ -47,15 +47,15 @@ Version is #{File.basename($0)} #{Utils::VERSION}.
47
47
  end
48
48
 
49
49
  args = go 'I:a:rceEbvh'
50
- args['h'] and usage
50
+ args[?h] and usage
51
51
  pattern = ARGV.shift or usage
52
52
  roots = (ARGV.empty? ? [ Dir.pwd ] : ARGV).map { |f| File.expand_path(f) }
53
53
 
54
- Term::ANSIColor.coloring = (STDIN.tty? && ENV['TERM'] !~ /dumb/) && !args['c']
54
+ Term::ANSIColor.coloring = (STDIN.tty? && ENV['TERM'] !~ /dumb/) && !args[?c]
55
55
  STDOUT.sync = true
56
56
  config = Utils::ConfigFile.new
57
57
  config.configure_from_paths
58
- args['b'] ||= config.discover.binary
58
+ args[?b] ||= config.discover.binary
59
59
  finder = Finder.new(
60
60
  :pattern => pattern,
61
61
  :args => args,
@@ -64,9 +64,9 @@ finder = Finder.new(
64
64
  ).search
65
65
 
66
66
  case
67
- when args['E']
67
+ when args[?E]
68
68
  edit_files finder.paths, pick: true
69
- when args['e']
69
+ when args[?e]
70
70
  edit_files finder.paths
71
71
  else
72
72
  puts finder.paths
data/bin/edit CHANGED
@@ -30,19 +30,19 @@ Version is #{File.basename($0)} #{Utils::VERSION}.
30
30
  end
31
31
 
32
32
  $opt = go 'p:S:c:g:wsmh'
33
- $opt['h'] and usage
33
+ $opt[?h] and usage
34
34
 
35
35
  config = Utils::ConfigFile.new
36
36
  config.configure_from_paths
37
37
 
38
38
  editor = Editor.new do |c|
39
- c.wait = $opt['w']
40
- c.pause_duration = ($opt['p'] || 1).to_i
41
- s = $opt['S'] and c.servername = s
42
- c.mkdir = $opt['m']
39
+ c.wait = $opt[?w]
40
+ c.pause_duration = ($opt[?p] || 1).to_i
41
+ s = $opt[?S] and c.servername = s
42
+ c.mkdir = $opt[?m]
43
43
  end
44
44
 
45
- if $opt['s']
45
+ if $opt[?s]
46
46
  begin
47
47
  until STDIN.eof?
48
48
  line = STDIN.gets
@@ -53,9 +53,9 @@ if $opt['s']
53
53
  exit 1
54
54
  end
55
55
  exit 0
56
- elsif command = $opt['c']
56
+ elsif command = $opt[?c]
57
57
  editor.edit_remote_send "\e:#{command}\n"
58
- elsif command = $opt['C']
58
+ elsif command = $opt[?C]
59
59
  editor.edit_remote_send command
60
60
  end
61
61
 
@@ -71,7 +71,7 @@ if argv.empty?
71
71
  argv << file.path
72
72
  end
73
73
  end
74
- case git_files_arg = $opt['g']
74
+ case git_files_arg = $opt[?g]
75
75
  when ?g
76
76
  argv.concat `git diff HEAD --name-only`.lines.map(&:chomp).uniq
77
77
  when /\A[mcdo]\z/
data/bin/enum CHANGED
@@ -150,18 +150,18 @@ $opts = {
150
150
  }.update(go('p:e:f:h')) do |o,default,set|
151
151
  set || default
152
152
  end
153
- usage if $opts['h'] || ARGV.size != 1
153
+ usage if $opts[?h] || ARGV.size != 1
154
154
  $ranges = ARGV.shift
155
- $limited = $opts['p'] ? Limited.new($opts['p']) : nil
155
+ $limited = $opts[?p] ? Limited.new($opts[?p]) : nil
156
156
  ranges = parse_ranges($ranges)
157
157
  generator = Generator.new(ranges)
158
- $opts['f'] ||= %w[ %s ] * generator.size * ':'
158
+ $opts[?f] ||= %w[ %s ] * generator.size * ':'
159
159
 
160
160
  generator.each do |tuple|
161
- if $opts['e']
162
- execute_command($opts['e'], $opts['f'], tuple)
161
+ if $opts[?e]
162
+ execute_command($opts[?e], $opts[?f], tuple)
163
163
  else
164
- puts $opts['f'] % tuple
164
+ puts $opts[?f] % tuple
165
165
  end
166
166
  end
167
167
  exit 0
data/bin/git-versions ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'tins/xt'
4
+ require 'term/ansicolor'
5
+ include Tins::GO
6
+
7
+ $opts = go 'r:v'
8
+
9
+ class String
10
+ include Term::ANSIColor
11
+ end
12
+
13
+ regexp = $opts[?r] && Regexp.new($opts[?r]) || /^v((?:\d+\.)*\d+)/
14
+
15
+ versions = `git tag`.lines.map(&:chomp).grep(regexp).sort_by { |x|
16
+ x[regexp, 1].version
17
+ }.reverse
18
+ versions.each_cons(2) do |new, old|
19
+ puts "Version #{new}".red.bold
20
+ if $opts[?v]
21
+ puts `git log --color --stat -u #{old}..#{new}`
22
+ else
23
+ puts `git log --color --stat #{old}..#{new}`
24
+ end
25
+ end
data/bin/irb_connect CHANGED
@@ -24,14 +24,14 @@ Version is #{File.basename($0)} #{Utils::VERSION}.
24
24
  end
25
25
 
26
26
 
27
- $opt = go 'e:r:p:l:h'
28
- $opt['h'] and usage
27
+ $opts = go 'e:r:p:l:h'
28
+ $opts[?h] and usage
29
29
 
30
- proxy = Utils::IRB::Service.connect($opt['r'], $opt['p'])
30
+ proxy = Utils::IRB::Service.connect($opts[?r], $opts[?p])
31
31
  case
32
- when load_path = $opt['l']
32
+ when load_path = $opts[?l]
33
33
  proxy.load(load_path)
34
- when code = $opt['e']
34
+ when code = $opts[?e]
35
35
  p proxy.eval(code)
36
36
  else
37
37
  puts proxy.eval(STDIN.read)
data/bin/myex CHANGED
@@ -49,7 +49,7 @@ when 'create'
49
49
  STDIN.grep(/^CREATE TABLE `([^`]+)` \(/) do |stmt|
50
50
  table = $1
51
51
  next unless ARGV.empty? or ARGV.member?(table)
52
- if opts['d']
52
+ if opts[?d]
53
53
  puts "DROP TABLE IF EXISTS `#{table}`;"
54
54
  warn "Dropped table #{table}."
55
55
  end
@@ -74,8 +74,8 @@ when 'insert'
74
74
  puts "SET FOREIGN_KEY_CHECKS = 0;"
75
75
  STDIN.grep(/^INSERT (?:IGNORE )?INTO `(#{ARGV.empty? ? '[^`]+' : ARGV * '|'})`/) do |stmt|
76
76
  table = $1
77
- stmt.sub!(/(^INSERT) (INTO)/, '\1 IGNORE \2') if opts['i']
78
- if opts['t'] and not truncated.key?(table)
77
+ stmt.sub!(/(^INSERT) (INTO)/, '\1 IGNORE \2') if opts[?i]
78
+ if opts[?t] and not truncated.key?(table)
79
79
  puts "TRUNCATE TABLE `#{table}`;"
80
80
  truncated[table] = true
81
81
  warn "Truncated table #{table}."
data/bin/path CHANGED
@@ -9,7 +9,7 @@ path_separator = RUBY_PLATFORM =~ /mswin32/ ? ';' : ':'
9
9
  path = (ENV['PATH'] || '').split(path_separator)
10
10
  path.map! { |part| File.expand_path(part) }
11
11
 
12
- $opt = go('e')
12
+ $opts = go('e')
13
13
 
14
14
  case cmd = ARGV.shift
15
15
  when 'prefix', 'postfix'
@@ -35,4 +35,4 @@ end
35
35
 
36
36
  path.uniq!
37
37
 
38
- puts "#{'export ' if $opt['e']}PATH=#{path * path_separator}"
38
+ puts "#{'export ' if $opt[?e]}PATH=#{path * path_separator}"
data/bin/probe CHANGED
@@ -73,7 +73,7 @@ end
73
73
  def connect_server
74
74
  DRb.start_service
75
75
  probe_server = DRbObject.new_with_uri($uri)
76
- if setting = $opt['C']
76
+ if setting = $opts[?C]
77
77
  case setting
78
78
  when /\A([^=]+)=([^=]+)\z/
79
79
  probe_server.env[$1] = $2
@@ -83,8 +83,8 @@ def connect_server
83
83
  usage
84
84
  end
85
85
  end
86
- if $opt['c']
87
- opts = $opt.subhash('n', 't').each_with_object([]) { |(k, v), a|
86
+ if $opts[?c]
87
+ opts = $opts.subhash('n', 't').each_with_object([]) { |(k, v), a|
88
88
  v.full? and a.concat [ "-#{k}", v ]
89
89
  }
90
90
  probe_server.enqueue opts + $args
@@ -101,23 +101,23 @@ if i = ARGV.index('--')
101
101
  else
102
102
  $args = ARGV.dup
103
103
  end
104
- $opt = go 'lct:n:u:C:h', $args
105
- $opt['h'] and usage
104
+ $opts = go 'lct:n:u:C:h', $args
105
+ $opts[?h] and usage
106
106
 
107
- $uri = $opt['u'] || 'drbunix:probe.socket'
107
+ $uri = $opts[?u] || 'drbunix:probe.socket'
108
108
 
109
109
  case
110
- when $opt['l']
110
+ when $opts[?l]
111
111
  start_server
112
112
  exit
113
- when $opt['c'], $opt['C']
113
+ when $opts[?c], $opts[?C]
114
114
  connect_server
115
115
  end
116
116
 
117
117
  $args.empty? and exit
118
118
  puts "Running tests in #{$args.inspect}"
119
119
 
120
- case ($opt['t'] || $config.probe.test_framework).to_sym
120
+ case ($opts[?t] || $config.probe.test_framework).to_sym
121
121
  when :rspec
122
122
  case
123
123
  when spring?
@@ -128,7 +128,7 @@ when :rspec
128
128
  rspec = [ find_cmd('rspec', 'spec') ] << '-rutils' << '-f' <<
129
129
  'Utils::LineFormatter'
130
130
  end
131
- if linenumber = $opt['n']
131
+ if linenumber = $opts[?n]
132
132
  cmd 'ruby', '-I', $config.probe.include_dirs_argument, *rspec, '-l',
133
133
  linenumber, *($args + testrunner_args)
134
134
  else
@@ -148,7 +148,7 @@ when :'test-unit'
148
148
  else
149
149
  testrb = find_cmd('testrb')
150
150
  end
151
- if testname = $opt['n']
151
+ if testname = $opts[?n]
152
152
  cmd 'ruby', '-I', $config.probe.include_dirs_argument, *testrb,
153
153
  '-n', testname, *($args + testrunner_args)
154
154
  else
@@ -170,7 +170,7 @@ when :'test-unit'
170
170
  end
171
171
  when :cucumber
172
172
  cucumber = find_cmd('cucumber')
173
- if linenumber = $opt['n']
173
+ if linenumber = $opts[?n]
174
174
  cmd 'ruby', cucumber, '-r', $config.probe.include_dirs_argument, '-l',
175
175
  linenumber, *($args + testrunner_args)
176
176
  else
data/bin/search CHANGED
@@ -125,7 +125,8 @@ 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
+ -b also search binary files
129
+ -g use git to determine author of the line
129
130
  -a CSET use only character set CSET from PATTERN
130
131
  -v be verbose
131
132
  -h display this help
@@ -135,12 +136,12 @@ Version is #{File.basename($0)} #{Utils::VERSION}.
135
136
  exit 1
136
137
  end
137
138
 
138
- args = go 'r:I:A:B:C:s:S:n:N:a:RciflLeEvbh'
139
- args['h'] and usage
139
+ args = go 'r:I:A:B:C:s:S:n:N:a:RciflLeEvbgh'
140
+ args[?h] and usage
140
141
  pattern = ARGV.shift or usage
141
142
  roots = (ARGV.empty? ? [ Dir.pwd ] : ARGV).map { |f| File.expand_path(f) }
142
143
 
143
- Term::ANSIColor.coloring = (STDIN.tty? && ENV['TERM'] !~ /dumb/) && !args['c']
144
+ Term::ANSIColor.coloring = (STDIN.tty? && ENV['TERM'] !~ /dumb/) && !args[?c]
144
145
  STDOUT.sync = true
145
146
  config = Utils::ConfigFile.new
146
147
  config.configure_from_paths
@@ -151,8 +152,8 @@ grepper = Grepper.new(
151
152
  :config => config
152
153
  ).search
153
154
  case
154
- when args['r'] then edit_files grepper.pattern, grepper.paths, replace: args['r']
155
- when args['E'] then edit_files grepper.pattern, grepper.paths, pick: true
156
- when args['e'] then edit_files grepper.pattern, grepper.paths
157
- when args['l'] then puts grepper.paths
155
+ when args[?r] then edit_files grepper.pattern, grepper.paths, replace: args[?r]
156
+ when args[?E] then edit_files grepper.pattern, grepper.paths, pick: true
157
+ when args[?e] then edit_files grepper.pattern, grepper.paths
158
+ when args[?l] then puts grepper.paths
158
159
  end
data/bin/serve CHANGED
File without changes
data/bin/ssh-tunnel CHANGED
@@ -49,9 +49,9 @@ config = Utils::ConfigFile.new
49
49
  arguments = ARGV
50
50
  opts = go 't:n:C:m:e:hNTd', arguments
51
51
 
52
- $DEBUG = opts['d']
52
+ $DEBUG = opts[?d]
53
53
 
54
- if opts['T']
54
+ if opts[?T]
55
55
  tunnels = PSTree.new.select { |pt| pt.user == ENV['USER'] && pt.cmd =~ /ssh.*-L/ }
56
56
  tunnels.map! do |pt|
57
57
  cmd = pt.cmd
@@ -63,7 +63,7 @@ if opts['T']
63
63
  exit 0
64
64
  end
65
65
 
66
- case opts['C']
66
+ case opts[?C]
67
67
  when 'ssh-default'
68
68
  STDOUT.puts SSH_CONFIG; exit
69
69
  when 'rc-default'
@@ -75,9 +75,9 @@ end
75
75
 
76
76
  config.configure_from_paths
77
77
 
78
- usage if opts['h'] or arguments.size != 1
78
+ usage if opts[?h] or arguments.size != 1
79
79
 
80
- if multiplexer = opts['m']
80
+ if multiplexer = opts[?m]
81
81
  config.ssh_tunnel.terminal_multiplexer = multiplexer
82
82
  end
83
83
 
@@ -96,11 +96,11 @@ ssh_dir = File.expand_path('~/.ssh')
96
96
  mkdir_p ssh_dir
97
97
  sock_file = "#{ssh_dir}/#{user}@#{remote}:#{rport}.sock"
98
98
  if env_user = ENV['USER']
99
- opts['n'] ||= env_user
99
+ opts[?n] ||= env_user
100
100
  else
101
- opts['n'] ||= 'session'
101
+ opts[?n] ||= 'session'
102
102
  end
103
- if opts['N']
103
+ if opts[?N]
104
104
  cmd "ssh -p #{rport} -S #{sock_file} #{user}@#{remote} #{config.ssh_tunnel.multiplexer_list}"
105
105
  else
106
106
  File.exist? sock_file and rm_f sock_file
@@ -109,7 +109,7 @@ else
109
109
  env << "COPY_REMOTE_HOST_PORT='#{t.bind_address}:#{t.port}'"
110
110
  tunnels << "-R #{t}"
111
111
  end
112
- opts['t'].to_a.each do |tunnel_spec|
112
+ opts[?t].to_a.each do |tunnel_spec|
113
113
  if arg = Utils::SshTunnelSpecification.new(tunnel_spec).valid?
114
114
  tunnels << "-L #{arg}"
115
115
  else
@@ -119,12 +119,12 @@ else
119
119
  config.ssh_tunnel.env.each do |var, val|
120
120
  ENV[var.to_s] = val.to_s
121
121
  end
122
- opts['e'].to_a.each do |setting|
122
+ opts[?e].to_a.each do |setting|
123
123
  var, val = setting.split('=', 2)
124
124
  ENV[var] = val
125
125
  end
126
126
  cmd "ssh -p #{rport} -Mt "\
127
127
  "-S #{sock_file} #{user}@#{remote} #{tunnels * ' '} "\
128
- "'env #{env * ' '} #{config.ssh_tunnel.multiplexer_new(opts['n'])} || "\
129
- "#{config.ssh_tunnel.multiplexer_attach(opts['n'])}'"
128
+ "'env #{env * ' '} #{config.ssh_tunnel.multiplexer_new(opts[?n])} || "\
129
+ "#{config.ssh_tunnel.multiplexer_attach(opts[?n])}'"
130
130
  end
data/bin/strip_spaces CHANGED
@@ -21,6 +21,7 @@ stripped.
21
21
 
22
22
  Options are
23
23
 
24
+ -t COLUMNS turn tabs into COLUMNS spaces
24
25
  -I SUFFIXES list of suffixes
25
26
  -h display this help
26
27
 
@@ -29,14 +30,14 @@ Version is #{File.basename($0)} #{Utils::VERSION}.
29
30
  exit 1
30
31
  end
31
32
 
32
- args = go 'I:h'
33
- args['h'] and usage
33
+ args = go 'I:t:h'
34
+ args[?h] and usage
34
35
 
35
36
  unless ARGV.empty?
36
37
  paths = ARGV.map { |p| File.expand_path(p) }
37
38
  end
38
39
 
39
- suffix = args['I'].ask_and_send(:split, /[\s,]+/).to_a
40
+ suffix = args[?I].ask_and_send(:split, /[\s,]+/).to_a
40
41
 
41
42
  config = Utils::ConfigFile.new
42
43
  config.configure_from_paths
@@ -52,12 +53,15 @@ if paths
52
53
  s.file? or next
53
54
  config.strip_spaces.skip?(bn) and next
54
55
  File.ascii?(filename) or next
55
- STDOUT.puts "Stripping spaces from #{filename.inspect}."
56
+ STDOUT.puts "Stripping spaces/tabs from #{filename.inspect}."
56
57
  secure_write(filename) do |output|
57
58
  File.open(filename) do |file|
58
59
  old_mode = file.stat.mode
59
60
  file.each do |line|
60
61
  line.gsub!(/[ \t\v]+$/, '')
62
+ if tabs = args[?t]
63
+ line.gsub!(/\t/, ' ' * Integer(tabs))
64
+ end
61
65
  output.write line
62
66
  end
63
67
  File.chmod old_mode, output.path
@@ -156,7 +156,7 @@ class Utils::ConfigFile
156
156
  end
157
157
 
158
158
  class SshTunnel < BlockConfig
159
- config :terminal_multiplexer, 'screen'
159
+ config :terminal_multiplexer, 'tmux'
160
160
 
161
161
  config :env, {}
162
162
 
data/lib/utils/finder.rb CHANGED
@@ -15,11 +15,11 @@ class Utils::Finder
15
15
  @roots = discover_roots(opts[:roots])
16
16
  @config = opts[:config] || Utils::ConfigFile.new
17
17
  pattern_opts = opts.subhash(:pattern) | {
18
- :cset => @args['a'],
18
+ :cset => @args[?a],
19
19
  :icase => @args.fetch('i', true),
20
20
  }
21
- @binary = @args['b']
22
- @pattern = @args['r'] ?
21
+ @binary = @args[?b]
22
+ @pattern = @args[?r] ?
23
23
  RegexpPattern.new(pattern_opts) :
24
24
  FuzzyPattern.new(pattern_opts)
25
25
  @paths = []
@@ -44,16 +44,16 @@ class Utils::Finder
44
44
 
45
45
  def search
46
46
  paths = []
47
- suffixes = @args['I'].ask_and_send(:split, /[\s,]+/).to_a
47
+ suffixes = @args[?I].ask_and_send(:split, /[\s,]+/).to_a
48
48
  find(*(@roots + [ { :suffix => suffixes } ])) do |filename|
49
49
  begin
50
50
  bn, s = filename.pathname.basename, filename.stat
51
51
  if !s || s.directory? && @config.discover.prune?(bn)
52
- @args['v'] and warn "Pruning #{filename.inspect}."
52
+ @args[?v] and warn "Pruning #{filename.inspect}."
53
53
  prune
54
54
  end
55
55
  if s.file? && @config.discover.skip?(bn)
56
- @args['v'] and warn "Skipping #{filename.inspect}."
56
+ @args[?v] and warn "Skipping #{filename.inspect}."
57
57
  next
58
58
  end
59
59
  paths << filename
@@ -62,7 +62,7 @@ class Utils::Finder
62
62
  paths.uniq!
63
63
  paths.map! { |p| a = File.split(p) ; a.unshift(p) ; a }
64
64
  paths = paths.map! do |path, dir, file|
65
- if do_match = attempt_match?(path) and @args['v']
65
+ if do_match = attempt_match?(path) and @args[?v]
66
66
  warn "Attempt match of #{path.inspect}"
67
67
  end
68
68
  if do_match and match = @pattern.match(path)
data/lib/utils/grepper.rb CHANGED
@@ -42,22 +42,22 @@ class Utils::Grepper
42
42
  end
43
43
  @paths = []
44
44
  pattern_opts = opts.subhash(:pattern) | {
45
- :cset => @args['a'],
46
- :icase => @args['i'],
45
+ :cset => @args[?a],
46
+ :icase => @args[?i],
47
47
  }
48
- @pattern = @args['R'] ?
48
+ @pattern = @args[?R] ?
49
49
  FuzzyPattern.new(pattern_opts) :
50
50
  RegexpPattern.new(pattern_opts)
51
51
  @name_pattern =
52
- if name_pattern = @args['N']
52
+ if name_pattern = @args[?N]
53
53
  RegexpPattern.new(:pattern => name_pattern)
54
- elsif name_pattern = @args['n']
54
+ elsif name_pattern = @args[?n]
55
55
  FuzzyPattern.new(:pattern => name_pattern)
56
56
  end
57
57
  @skip_pattern =
58
- if skip_pattern = @args['S']
58
+ if skip_pattern = @args[?S]
59
59
  RegexpPattern.new(:pattern => skip_pattern)
60
- elsif skip_pattern = @args['s']
60
+ elsif skip_pattern = @args[?s]
61
61
  FuzzyPattern.new(:pattern => skip_pattern)
62
62
  end
63
63
  end
@@ -71,40 +71,40 @@ class Utils::Grepper
71
71
  @output = []
72
72
  bn, s = File.basename(filename), File.stat(filename)
73
73
  if !s || s.directory? && @config.search.prune?(bn)
74
- @args['v'] and warn "Pruning #{filename.inspect}."
74
+ @args[?v] and warn "Pruning #{filename.inspect}."
75
75
  prune
76
76
  end
77
77
  if s.file? && !@config.search.skip?(bn) &&
78
78
  (!@name_pattern || @name_pattern.match(bn))
79
79
  then
80
- File.open(filename, 'rb') do |file|
81
- if file.binary? != true
82
- @args['v'] and warn "Matching #{filename.inspect}."
83
- if @args['f']
80
+ File.open(filename, 'rb', encoding: Encoding::UTF_8) do |file|
81
+ if @args[?b] && !@args[?g] || file.binary? != true
82
+ @args[?v] and warn "Matching #{filename.inspect}."
83
+ if @args[?f]
84
84
  @output << filename
85
85
  else
86
86
  match_lines file
87
87
  end
88
88
  else
89
- @args['v'] and warn "Skipping binary file #{filename.inspect}."
89
+ @args[?v] and warn "Skipping binary file #{filename.inspect}."
90
90
  end
91
91
  end
92
92
  else
93
- @args['v'] and warn "Skipping #{filename.inspect}."
93
+ @args[?v] and warn "Skipping #{filename.inspect}."
94
94
  end
95
95
  unless @output.empty?
96
96
  case
97
- when @args['b']
97
+ when @args[?g]
98
98
  @output.uniq!
99
99
  @output.each do |l|
100
100
  blamer = LineBlamer.for_line(l)
101
101
  if blame = blamer.perform
102
102
  blame.sub!(/^[0-9a-f^]+/) { Term::ANSIColor.yellow($&) }
103
103
  blame.sub!(/\(([^)]+)\)/) { "(#{Term::ANSIColor.red($1)})" }
104
- puts "#{l} #{blame}"
104
+ puts "#{blame.chomp} #{Term::ANSIColor.blue(l)}"
105
105
  end
106
106
  end
107
- when @args['l'], @args['e'], @args['E'], @args['r']
107
+ when @args[?l], @args[?e], @args[?E], @args[?r]
108
108
  @output.uniq!
109
109
  @paths.concat @output
110
110
  else
@@ -122,21 +122,21 @@ class Utils::Grepper
122
122
  line[m.begin(0)...m.end(0)] = black on_white m[0]
123
123
  @queue and @queue << line
124
124
  case
125
- when @args['l']
125
+ when @args[?l]
126
126
  @output << @filename
127
- when @args['L'], @args['r'], @args['b']
127
+ when @args[?L], @args[?r], @args[?g]
128
128
  @output << "#{@filename}:#{file.lineno}"
129
- when @args['e'], @args['E']
129
+ when @args[?e], @args[?E]
130
130
  @output << "#{@filename}:#{file.lineno}"
131
131
  break
132
132
  else
133
133
  @output << red("#{@filename}:#{file.lineno}")
134
- if @args['B'] or @args['C']
134
+ if @args[?B] or @args[?C]
135
135
  @output.concat @queue.data
136
136
  else
137
137
  @output << line
138
138
  end
139
- if @args['A'] or @args['C']
139
+ if @args[?A] or @args[?C]
140
140
  where = file.tell
141
141
  lineno = file.lineno
142
142
  @queue.max_size.times do
@@ -156,7 +156,7 @@ class Utils::Grepper
156
156
  end
157
157
 
158
158
  def search
159
- suffixes = @args['I'].ask_and_send(:split, /[\s,]+/).to_a
159
+ suffixes = @args[?I].ask_and_send(:split, /[\s,]+/).to_a
160
160
  find(*(@roots + [ { :suffix => suffixes } ])) do |filename|
161
161
  match(filename)
162
162
  end
@@ -8,6 +8,14 @@ module Utils
8
8
  location = line.source_location and new *location
9
9
  end
10
10
 
11
+ def self.blame(line)
12
+ blamer = for_line(line)
13
+ if blame = blamer.perform
14
+ blame.sub!(/^[0-9a-f^]+/) { Term::ANSIColor.yellow($&) }
15
+ blame.sub!(/\(([^)]+)\)/) { "(#{Term::ANSIColor.red($1)})" }
16
+ end
17
+ end
18
+
11
19
  def perform(options = '')
12
20
  `git 2>/dev/null blame #{options} -L #@lineno,+1 "#@file"`.full?
13
21
  end
@@ -13,6 +13,8 @@ module Utils
13
13
 
14
14
  def method_missing(*a, &b)
15
15
  @matcher.__send__(*a, &b)
16
+ rescue ArgumentError => e
17
+ raise e unless e.message.include?('invalid byte sequence in UTF-8')
16
18
  end
17
19
  end
18
20
 
@@ -35,7 +35,7 @@ module Utils
35
35
  end
36
36
 
37
37
  def inspect
38
- ok_colorize("Job##{id} #{args.map { |a| a.include?(' ') ? a.inspect : a } * ' '}")
38
+ ok_colorize("#{id} #{args.map { |a| a.include?(' ') ? a.inspect : a } * ' '}")
39
39
  end
40
40
 
41
41
  alias to_s inspect
data/lib/utils/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Utils
2
2
  # Utils version
3
- VERSION = '0.8.0'
3
+ VERSION = '0.9.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
data/utils.gemspec CHANGED
@@ -1,45 +1,45 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: utils 0.8.0 ruby lib
2
+ # stub: utils 0.9.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
- s.name = "utils"
6
- s.version = "0.8.0"
5
+ s.name = "utils".freeze
6
+ s.version = "0.9.0"
7
7
 
8
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
- s.require_paths = ["lib"]
10
- s.authors = ["Florian Frank"]
11
- s.date = "2016-09-30"
12
- s.description = "This ruby gem provides some useful command line utilities"
13
- s.email = "flori@ping.de"
14
- s.executables = ["blameline", "brakeman2err", "chroot-exec", "chroot-libs", "classify", "create_tags", "dialog-pick", "discover", "edit", "edit_wait", "enum", "errf", "git-empty", "irb_connect", "json_check", "long_lines", "myex", "number_files", "on_change", "path", "probe", "remote_copy", "rssr", "same_files", "search", "sedit", "serve", "ssh-tunnel", "strip_spaces", "unquarantine_apps", "untest", "utils-utilsrc", "vacuum_firefox_sqlite", "xmp"]
15
- s.extra_rdoc_files = ["README.md", "lib/utils.rb", "lib/utils/config_file.rb", "lib/utils/editor.rb", "lib/utils/file_xt.rb", "lib/utils/finder.rb", "lib/utils/grepper.rb", "lib/utils/irb.rb", "lib/utils/irb/service.rb", "lib/utils/line_blamer.rb", "lib/utils/line_formatter.rb", "lib/utils/md5.rb", "lib/utils/patterns.rb", "lib/utils/probe_server.rb", "lib/utils/ssh_tunnel_specification.rb", "lib/utils/version.rb", "lib/utils/xt/source_location_extension.rb"]
16
- s.files = [".gitignore", "COPYING", "Gemfile", "README.md", "Rakefile", "VERSION", "bin/blameline", "bin/brakeman2err", "bin/chroot-exec", "bin/chroot-libs", "bin/classify", "bin/create_tags", "bin/dialog-pick", "bin/discover", "bin/edit", "bin/edit_wait", "bin/enum", "bin/errf", "bin/git-empty", "bin/irb_connect", "bin/json_check", "bin/long_lines", "bin/myex", "bin/number_files", "bin/on_change", "bin/path", "bin/probe", "bin/remote_copy", "bin/rssr", "bin/same_files", "bin/search", "bin/sedit", "bin/serve", "bin/ssh-tunnel", "bin/strip_spaces", "bin/unquarantine_apps", "bin/untest", "bin/utils-utilsrc", "bin/vacuum_firefox_sqlite", "bin/xmp", "lib/utils.rb", "lib/utils/config_file.rb", "lib/utils/editor.rb", "lib/utils/file_xt.rb", "lib/utils/finder.rb", "lib/utils/grepper.rb", "lib/utils/irb.rb", "lib/utils/irb/service.rb", "lib/utils/line_blamer.rb", "lib/utils/line_formatter.rb", "lib/utils/md5.rb", "lib/utils/patterns.rb", "lib/utils/probe_server.rb", "lib/utils/ssh_tunnel_specification.rb", "lib/utils/version.rb", "lib/utils/xt/source_location_extension.rb", "utils.gemspec", "utils.gemspec "]
17
- s.homepage = "http://github.com/flori/utils"
18
- s.rdoc_options = ["--title", "Utils - Some useful command line utilities", "--main", "README.md"]
19
- s.rubygems_version = "2.5.1"
20
- s.summary = "Some useful command line utilities"
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
+ s.require_paths = ["lib".freeze]
10
+ s.authors = ["Florian Frank".freeze]
11
+ s.date = "2017-02-07"
12
+ s.description = "This ruby gem provides some useful command line utilities".freeze
13
+ s.email = "flori@ping.de".freeze
14
+ s.executables = ["ascii7".freeze, "blameline".freeze, "brakeman2err".freeze, "chroot-exec".freeze, "chroot-libs".freeze, "classify".freeze, "create_tags".freeze, "dialog-pick".freeze, "discover".freeze, "edit".freeze, "edit_wait".freeze, "enum".freeze, "errf".freeze, "git-empty".freeze, "git-versions".freeze, "irb_connect".freeze, "json_check".freeze, "long_lines".freeze, "myex".freeze, "number_files".freeze, "on_change".freeze, "path".freeze, "probe".freeze, "remote_copy".freeze, "rssr".freeze, "same_files".freeze, "search".freeze, "sedit".freeze, "serve".freeze, "ssh-tunnel".freeze, "strip_spaces".freeze, "unquarantine_apps".freeze, "untest".freeze, "utils-utilsrc".freeze, "vacuum_firefox_sqlite".freeze, "xmp".freeze]
15
+ s.extra_rdoc_files = ["README.md".freeze, "lib/utils.rb".freeze, "lib/utils/config_file.rb".freeze, "lib/utils/editor.rb".freeze, "lib/utils/file_xt.rb".freeze, "lib/utils/finder.rb".freeze, "lib/utils/grepper.rb".freeze, "lib/utils/irb.rb".freeze, "lib/utils/irb/service.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_server.rb".freeze, "lib/utils/ssh_tunnel_specification.rb".freeze, "lib/utils/version.rb".freeze, "lib/utils/xt/source_location_extension.rb".freeze]
16
+ s.files = [".gitignore".freeze, "COPYING".freeze, "Gemfile".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "bin/ascii7".freeze, "bin/blameline".freeze, "bin/brakeman2err".freeze, "bin/chroot-exec".freeze, "bin/chroot-libs".freeze, "bin/classify".freeze, "bin/create_tags".freeze, "bin/dialog-pick".freeze, "bin/discover".freeze, "bin/edit".freeze, "bin/edit_wait".freeze, "bin/enum".freeze, "bin/errf".freeze, "bin/git-empty".freeze, "bin/git-versions".freeze, "bin/irb_connect".freeze, "bin/json_check".freeze, "bin/long_lines".freeze, "bin/myex".freeze, "bin/number_files".freeze, "bin/on_change".freeze, "bin/path".freeze, "bin/probe".freeze, "bin/remote_copy".freeze, "bin/rssr".freeze, "bin/same_files".freeze, "bin/search".freeze, "bin/sedit".freeze, "bin/serve".freeze, "bin/ssh-tunnel".freeze, "bin/strip_spaces".freeze, "bin/unquarantine_apps".freeze, "bin/untest".freeze, "bin/utils-utilsrc".freeze, "bin/vacuum_firefox_sqlite".freeze, "bin/xmp".freeze, "lib/utils.rb".freeze, "lib/utils/config_file.rb".freeze, "lib/utils/editor.rb".freeze, "lib/utils/file_xt.rb".freeze, "lib/utils/finder.rb".freeze, "lib/utils/grepper.rb".freeze, "lib/utils/irb.rb".freeze, "lib/utils/irb/service.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_server.rb".freeze, "lib/utils/ssh_tunnel_specification.rb".freeze, "lib/utils/version.rb".freeze, "lib/utils/xt/source_location_extension.rb".freeze, "utils.gemspec".freeze]
17
+ s.homepage = "http://github.com/flori/utils".freeze
18
+ s.rdoc_options = ["--title".freeze, "Utils - Some useful command line utilities".freeze, "--main".freeze, "README.md".freeze]
19
+ s.rubygems_version = "2.6.8".freeze
20
+ s.summary = "Some useful command line utilities".freeze
21
21
 
22
22
  if s.respond_to? :specification_version then
23
23
  s.specification_version = 4
24
24
 
25
25
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
- s.add_development_dependency(%q<gem_hadar>, ["~> 1.8.0"])
27
- s.add_runtime_dependency(%q<tins>, ["~> 1.8"])
28
- s.add_runtime_dependency(%q<term-ansicolor>, ["~> 1.3"])
29
- s.add_runtime_dependency(%q<pstree>, ["~> 0.1"])
30
- s.add_runtime_dependency(%q<pry-editline>, [">= 0"])
26
+ s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.9.1"])
27
+ s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.8"])
28
+ s.add_runtime_dependency(%q<term-ansicolor>.freeze, ["~> 1.3"])
29
+ s.add_runtime_dependency(%q<pstree>.freeze, ["~> 0.1"])
30
+ s.add_runtime_dependency(%q<pry-editline>.freeze, [">= 0"])
31
31
  else
32
- s.add_dependency(%q<gem_hadar>, ["~> 1.8.0"])
33
- s.add_dependency(%q<tins>, ["~> 1.8"])
34
- s.add_dependency(%q<term-ansicolor>, ["~> 1.3"])
35
- s.add_dependency(%q<pstree>, ["~> 0.1"])
36
- s.add_dependency(%q<pry-editline>, [">= 0"])
32
+ s.add_dependency(%q<gem_hadar>.freeze, ["~> 1.9.1"])
33
+ s.add_dependency(%q<tins>.freeze, ["~> 1.8"])
34
+ s.add_dependency(%q<term-ansicolor>.freeze, ["~> 1.3"])
35
+ s.add_dependency(%q<pstree>.freeze, ["~> 0.1"])
36
+ s.add_dependency(%q<pry-editline>.freeze, [">= 0"])
37
37
  end
38
38
  else
39
- s.add_dependency(%q<gem_hadar>, ["~> 1.8.0"])
40
- s.add_dependency(%q<tins>, ["~> 1.8"])
41
- s.add_dependency(%q<term-ansicolor>, ["~> 1.3"])
42
- s.add_dependency(%q<pstree>, ["~> 0.1"])
43
- s.add_dependency(%q<pry-editline>, [">= 0"])
39
+ s.add_dependency(%q<gem_hadar>.freeze, ["~> 1.9.1"])
40
+ s.add_dependency(%q<tins>.freeze, ["~> 1.8"])
41
+ s.add_dependency(%q<term-ansicolor>.freeze, ["~> 1.3"])
42
+ s.add_dependency(%q<pstree>.freeze, ["~> 0.1"])
43
+ s.add_dependency(%q<pry-editline>.freeze, [">= 0"])
44
44
  end
45
45
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-30 00:00:00.000000000 Z
11
+ date: 2017-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.8.0
19
+ version: 1.9.1
20
20
  type: :development
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: 1.8.0
26
+ version: 1.9.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: tins
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -83,6 +83,7 @@ dependencies:
83
83
  description: This ruby gem provides some useful command line utilities
84
84
  email: flori@ping.de
85
85
  executables:
86
+ - ascii7
86
87
  - blameline
87
88
  - brakeman2err
88
89
  - chroot-exec
@@ -96,6 +97,7 @@ executables:
96
97
  - enum
97
98
  - errf
98
99
  - git-empty
100
+ - git-versions
99
101
  - irb_connect
100
102
  - json_check
101
103
  - long_lines
@@ -143,6 +145,7 @@ files:
143
145
  - README.md
144
146
  - Rakefile
145
147
  - VERSION
148
+ - bin/ascii7
146
149
  - bin/blameline
147
150
  - bin/brakeman2err
148
151
  - bin/chroot-exec
@@ -156,6 +159,7 @@ files:
156
159
  - bin/enum
157
160
  - bin/errf
158
161
  - bin/git-empty
162
+ - bin/git-versions
159
163
  - bin/irb_connect
160
164
  - bin/json_check
161
165
  - bin/long_lines
@@ -194,7 +198,6 @@ files:
194
198
  - lib/utils/version.rb
195
199
  - lib/utils/xt/source_location_extension.rb
196
200
  - utils.gemspec
197
- - 'utils.gemspec '
198
201
  homepage: http://github.com/flori/utils
199
202
  licenses: []
200
203
  metadata: {}
@@ -218,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
221
  version: '0'
219
222
  requirements: []
220
223
  rubyforge_project:
221
- rubygems_version: 2.5.1
224
+ rubygems_version: 2.6.8
222
225
  signing_key:
223
226
  specification_version: 4
224
227
  summary: Some useful command line utilities
data/utils.gemspec DELETED
File without changes