utils 0.11.0 → 0.12.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
  SHA256:
3
- metadata.gz: 3809eaf7bad02676dfb6af1ea42d81eccdb8c736844259c643d7c664f09deae4
4
- data.tar.gz: ddbeb6bf9c0ef761f4178b214128450a5aab0f3f3410350d1f0221c0699c231a
3
+ metadata.gz: 30ee29850e1dd83ba2674daf3545174878b20425fe225e97e831b77ce6d161f5
4
+ data.tar.gz: d223fd2dde07b9610a59465a356df56e6043b8a71cd32aa3921ececd1c380227
5
5
  SHA512:
6
- metadata.gz: 037bad1cf871c2f1eba57bc9b0206262105e6b481fd2de1fee7f18b5602cb283e3219ba5a254ec60f0dca3c54b2ac5d63e035a75c0cb910d42279ca4c2329749
7
- data.tar.gz: c655f58309f4aca09eccfc35b440daed4d4e7de35b8300e530231e15dc896c90fe11dc027a34404b7ede8fefdd167cb795a91e27830dc628427fd2c8922d69d8
6
+ metadata.gz: 4a88f6dfd850e88ecae6881dc60e2d31ba6e88b700f455fedf5fe6a3d60ccad82d56c8461d0206d35e6f3369710d4a902922f0aa97bdde5404a0dcd9df0240ed
7
+ data.tar.gz: 7bd475966ada4a6a5f292d8a8af1c220c784e28a5c8b60dc10aa98e22dff62824eb37d1b8d46ef93ba4fe6f74015283167cf757213c330ab0f01b918f23a39a7
data/Rakefile CHANGED
@@ -21,6 +21,7 @@ GemHadar do
21
21
  dependency 'pstree', '~>0.1'
22
22
  dependency 'pry-editline'
23
23
  dependency 'infobar'
24
+ dependency 'mize'
24
25
 
25
26
  install_library do
26
27
  libdir = CONFIG["sitelibdir"]
@@ -39,6 +40,6 @@ GemHadar do
39
40
  install(file, bindir, :mode => 0755)
40
41
  end
41
42
  end
42
- ENV['NO_GEMS'].to_i == 1 or sh 'gem install tins term-ansicolor pstree pry-editline infobar'
43
+ ENV['NO_GEMS'].to_i == 1 or sh 'gem install tins term-ansicolor pstree pry-editline infobar mize'
43
44
  end
44
45
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.11.0
1
+ 0.12.0
data/bin/discover CHANGED
@@ -5,7 +5,7 @@ include Utils
5
5
  require 'tins/xt'
6
6
  include Tins::GO
7
7
 
8
- def edit_files(paths, pick: false)
8
+ def edit_files(*paths, pick: false, wait: true)
9
9
  editor = Utils::Editor.new
10
10
  if pick
11
11
  if paths.size > 1
@@ -17,14 +17,14 @@ def edit_files(paths, pick: false)
17
17
  end
18
18
  editor.edit(path.strip)
19
19
  else
20
- editor.wait = true
20
+ editor.wait = wait
21
21
  editor.edit(*paths)
22
22
  end
23
23
  end
24
24
 
25
25
  def usage
26
26
  puts <<-EOT
27
- Usage: #{File.basename($0)} [OPTS] PATTERN [PATHS]
27
+ Usage: #{File.basename($0)} [OPTS] [PATTERN] [PATHS]
28
28
 
29
29
  PATTERN is a pattern expression which is find the files. PATHS are the
30
30
  directory and file paths that are searched.
@@ -42,6 +42,7 @@ Options are
42
42
  -d match also directories
43
43
  -v be verbose
44
44
  -n NUMBER the first NUMBER of matches is returned
45
+ -s search by interactively inputting PATTERN
45
46
  -h display this help
46
47
 
47
48
  Version is #{File.basename($0)} #{Utils::VERSION}.
@@ -49,7 +50,7 @@ Version is #{File.basename($0)} #{Utils::VERSION}.
49
50
  exit 1
50
51
  end
51
52
 
52
- args = go 'n:I:i:a:p:creEvdh'
53
+ args = go 'n:I:i:a:p:creEvdsh'
53
54
  args[?h] and usage
54
55
 
55
56
  Term::ANSIColor.coloring = (STDIN.tty? && ENV['TERM'] !~ /dumb/) && !args[?c]
@@ -59,28 +60,57 @@ config.configure_from_paths
59
60
  args[?b] ||= config.discover.binary
60
61
  args[?n] ||= config.discover.max_matches
61
62
 
62
- pattern = ARGV.shift || ''
63
+ if args[?s]
64
+ pattern = ''
65
+ else
66
+ pattern = ARGV.shift || ''
67
+ end
63
68
  roots = (ARGV.empty? ? [ Dir.pwd ] : ARGV).map { |f| File.expand_path(f) }
64
69
 
65
- finder = Finder.new(
66
- :pattern => pattern,
67
- :args => args,
68
- :roots => roots,
69
- :config => config
70
- )
70
+ finder = -> * {
71
+ Finder.new(
72
+ :pattern => pattern,
73
+ :args => args,
74
+ :roots => roots,
75
+ :config => config
76
+ )
77
+ }
71
78
 
72
79
  case
80
+ when args[?s]
81
+ f = nil
82
+ pattern = pattern.dup
83
+ args[?n] = Term::ANSIColor.terminal_lines - 1
84
+ path = nil
85
+ found = Utils::InteractiveSearch.new(
86
+ query: -> answer {
87
+ pattern.replace answer
88
+ f = finder.()
89
+ f.search.output.join(?\n)
90
+ },
91
+ found: -> answer {
92
+ f and path = f.paths.first
93
+ },
94
+ output: STDERR
95
+ ).start
96
+ if found
97
+ if args[?e]
98
+ edit_files path, wait: false
99
+ else
100
+ found and puts path
101
+ end
102
+ exit 0
103
+ else
104
+ exit 1
105
+ end
106
+ when args[?E]
107
+ edit_files *finder.().paths, pick: true
108
+ when args[?e]
109
+ edit_files *finder.().search.paths
73
110
  when pattern.empty? && args[?r]
74
111
  exit
75
112
  when pattern.empty?
76
113
  usage
77
- when args[?E]
78
- finder.search
79
- edit_files finder.paths, pick: true
80
- when args[?e]
81
- finder.search
82
- edit_files finder.paths
83
114
  else
84
- finder.search
85
- puts finder.output
115
+ puts finder.().search.output
86
116
  end
data/bin/myex CHANGED
@@ -21,12 +21,12 @@ Usage: #{File.basename($0)} list|create|truncate|insert|replace|search [OPTION]
21
21
 
22
22
  - truncate: all tables or the given TABLES, if they exist.
23
23
 
24
- - insert: extract insert statemnts from the backup. If TABLES are given,
24
+ - insert: extract insert statements from the backup. If TABLES are given,
25
25
  extract only those statements for these TABLES.
26
26
  -t if this OPTION is given, truncate the table, before starting
27
27
  to insert.
28
28
 
29
- - replace: extract insert statemnts from the backup, and convert them
29
+ - replace: extract insert statements from the backup, and convert them
30
30
  into replace statements. If TABLES are given, extract only
31
31
  those statements for these TABLES.
32
32
 
data/lib/utils.rb CHANGED
@@ -10,6 +10,7 @@ module Utils
10
10
  require 'utils/probe_server'
11
11
  require 'utils/ssh_tunnel_specification'
12
12
  require 'utils/line_blamer'
13
+ require 'utils/interactive_search'
13
14
  begin
14
15
  require 'utils/line_formatter'
15
16
  rescue LoadError
data/lib/utils/finder.rb CHANGED
@@ -3,6 +3,7 @@ require 'tins/xt'
3
3
  require 'tempfile'
4
4
  require 'digest/md5'
5
5
  require 'fileutils'
6
+ require 'mize'
6
7
 
7
8
  class ::File
8
9
  include Utils::FileXt
@@ -76,6 +77,7 @@ class Utils::Finder
76
77
  paths
77
78
  end
78
79
 
80
+ memoize method:
79
81
  def load_paths
80
82
  lines = File.readlines(index_path)
81
83
  @args[?v] and warn "Loaded index #{index_path.inspect}."
@@ -90,6 +92,7 @@ class Utils::Finder
90
92
  path = index_path
91
93
  @args[?v] and warn "Resetting index #{path.inspect}."
92
94
  FileUtils.rm_f path
95
+ mize_cache_clear
93
96
  end
94
97
 
95
98
  def search_index
@@ -134,8 +137,8 @@ class Utils::Finder
134
137
  paths.compact!
135
138
  @paths, @output = paths.sort.transpose.values_at(-2, -1)
136
139
  if n = @args[?n]&.to_i
137
- @paths = @paths.first(n)
138
- @output = @output.first(n)
140
+ @paths = @paths&.first(n) || []
141
+ @output = @output&.first(n) || []
139
142
  end
140
143
  self
141
144
  end
@@ -0,0 +1,55 @@
1
+ require 'term/ansicolor'
2
+ class Utils::InteractiveSearch
3
+ include Term::ANSIColor
4
+
5
+ def initialize(query:, found:, output: STDOUT, prompt: 'Search? %s')
6
+ @query = query
7
+ @found = found
8
+ @output = output
9
+ @prompt = prompt
10
+ @answer = ''
11
+ end
12
+
13
+ def start
14
+ @output.print clear_screen
15
+ loop do
16
+ @output.print move_home(@prompt % @answer)
17
+ case getc
18
+ when true
19
+ @output.print clear_screen move_home reset
20
+ return !!@found.(@answer)
21
+ when false
22
+ return false
23
+ end
24
+ result = @query.(@answer)
25
+ @output.print clear_screen
26
+ unless @answer.empty?
27
+ @output.print clear_screen move_to_line(2, result)
28
+ end
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def getc
35
+ system 'stty raw -echo'
36
+ c = STDIN.getc
37
+ system 'stty cooked echo'
38
+ case c
39
+ when "\x03", "\e"
40
+ false
41
+ when ?\r
42
+ true
43
+ when "\x7f"
44
+ @answer.chop!
45
+ nil
46
+ when "\v"
47
+ @answer.clear
48
+ when /\A[\x00-\x1f]\z/
49
+ nil
50
+ else
51
+ @answer << c
52
+ nil
53
+ end
54
+ end
55
+ end
data/lib/utils/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Utils
2
2
  # Utils version
3
- VERSION = '0.11.0'
3
+ VERSION = '0.12.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,22 +1,22 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: utils 0.11.0 ruby lib
2
+ # stub: utils 0.12.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "utils".freeze
6
- s.version = "0.11.0"
6
+ s.version = "0.12.0"
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]
10
10
  s.authors = ["Florian Frank".freeze]
11
- s.date = "2018-10-31"
11
+ s.date = "2019-03-04"
12
12
  s.description = "This ruby gem provides some useful command line utilities".freeze
13
13
  s.email = "flori@ping.de".freeze
14
14
  s.executables = ["discover".freeze, "classify".freeze, "sedit".freeze, "irb_connect".freeze, "ascii7".freeze, "path".freeze, "enum".freeze, "unquarantine_apps".freeze, "ssh-tunnel".freeze, "xmp".freeze, "brakeman2err".freeze, "search".freeze, "chroot-exec".freeze, "edit".freeze, "tmproc".freeze, "json_check".freeze, "edit_wait".freeze, "errf".freeze, "untest".freeze, "blameline".freeze, "remote_copy".freeze, "git-empty".freeze, "vacuum_firefox_sqlite".freeze, "same_files".freeze, "chroot-libs".freeze, "git-versions".freeze, "strip_spaces".freeze, "number_files".freeze, "rssr".freeze, "serve".freeze, "vcf2alias".freeze, "on_change".freeze, "utils-utilsrc".freeze, "myex".freeze, "long_lines".freeze, "dialog-pick".freeze, "probe".freeze, "create_tags".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/tmproc".freeze, "bin/unquarantine_apps".freeze, "bin/untest".freeze, "bin/utils-utilsrc".freeze, "bin/vacuum_firefox_sqlite".freeze, "bin/vcf2alias".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]
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/interactive_search.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/tmproc".freeze, "bin/unquarantine_apps".freeze, "bin/untest".freeze, "bin/utils-utilsrc".freeze, "bin/vacuum_firefox_sqlite".freeze, "bin/vcf2alias".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/interactive_search.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
17
  s.homepage = "http://github.com/flori/utils".freeze
18
18
  s.rdoc_options = ["--title".freeze, "Utils - Some useful command line utilities".freeze, "--main".freeze, "README.md".freeze]
19
- s.rubygems_version = "2.7.7".freeze
19
+ s.rubygems_version = "3.0.2".freeze
20
20
  s.summary = "Some useful command line utilities".freeze
21
21
 
22
22
  if s.respond_to? :specification_version then
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  s.add_runtime_dependency(%q<pstree>.freeze, ["~> 0.1"])
30
30
  s.add_runtime_dependency(%q<pry-editline>.freeze, [">= 0"])
31
31
  s.add_runtime_dependency(%q<infobar>.freeze, [">= 0"])
32
+ s.add_runtime_dependency(%q<mize>.freeze, [">= 0"])
32
33
  else
33
34
  s.add_dependency(%q<gem_hadar>.freeze, ["~> 1.9.1"])
34
35
  s.add_dependency(%q<tins>.freeze, ["~> 1.14"])
@@ -36,6 +37,7 @@ Gem::Specification.new do |s|
36
37
  s.add_dependency(%q<pstree>.freeze, ["~> 0.1"])
37
38
  s.add_dependency(%q<pry-editline>.freeze, [">= 0"])
38
39
  s.add_dependency(%q<infobar>.freeze, [">= 0"])
40
+ s.add_dependency(%q<mize>.freeze, [">= 0"])
39
41
  end
40
42
  else
41
43
  s.add_dependency(%q<gem_hadar>.freeze, ["~> 1.9.1"])
@@ -44,5 +46,6 @@ Gem::Specification.new do |s|
44
46
  s.add_dependency(%q<pstree>.freeze, ["~> 0.1"])
45
47
  s.add_dependency(%q<pry-editline>.freeze, [">= 0"])
46
48
  s.add_dependency(%q<infobar>.freeze, [">= 0"])
49
+ s.add_dependency(%q<mize>.freeze, [">= 0"])
47
50
  end
48
51
  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.11.0
4
+ version: 0.12.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: 2018-10-31 00:00:00.000000000 Z
11
+ date: 2019-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mize
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: This ruby gem provides some useful command line utilities
98
112
  email: flori@ping.de
99
113
  executables:
@@ -144,6 +158,7 @@ extra_rdoc_files:
144
158
  - lib/utils/file_xt.rb
145
159
  - lib/utils/finder.rb
146
160
  - lib/utils/grepper.rb
161
+ - lib/utils/interactive_search.rb
147
162
  - lib/utils/irb.rb
148
163
  - lib/utils/irb/service.rb
149
164
  - lib/utils/line_blamer.rb
@@ -205,6 +220,7 @@ files:
205
220
  - lib/utils/file_xt.rb
206
221
  - lib/utils/finder.rb
207
222
  - lib/utils/grepper.rb
223
+ - lib/utils/interactive_search.rb
208
224
  - lib/utils/irb.rb
209
225
  - lib/utils/irb/service.rb
210
226
  - lib/utils/line_blamer.rb
@@ -238,8 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
254
  - !ruby/object:Gem::Version
239
255
  version: '0'
240
256
  requirements: []
241
- rubyforge_project:
242
- rubygems_version: 2.7.7
257
+ rubygems_version: 3.0.2
243
258
  signing_key:
244
259
  specification_version: 4
245
260
  summary: Some useful command line utilities