utils 0.34.0 → 0.36.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: 7555fc93b044b6664d90d4e459d730a2f0027ba4a266af8577ac972163a91710
4
- data.tar.gz: 5c22e9f713f59a2e2cedf64eb0e44746bd86ebd5aa40ea38a88f11524ce53ff7
3
+ metadata.gz: ba7d9a5d2f90097b79382fce03e1896767030b54cf497a9660ec41fd64ff84b0
4
+ data.tar.gz: d71a031ff72850f73f9ca0d29b42f45583044910a9c87c75a3860d2318d0567e
5
5
  SHA512:
6
- metadata.gz: 307f459fab4c993a09590af3b2b4de2a8e1ec263a40085685a95721374c36da8107a0d9a1bdb3ab15c9b8707b46a1ab45bbb1909d6046958a14cbf31c7489214
7
- data.tar.gz: 520ca2fa9e534f9341a565c424ab2ba1d7549e72586500cdf2bd41a1c993d4ecbfbd84d8f86b038a0171158bd5a93be268201ce5b35037d8e031bf5c6eaf6bdb
6
+ metadata.gz: 11cb9e1b968778dda0b0267bde2002c4a53e41da829a6411cd26d92aeb9978c804f3949d4dfc422feceaa526d644fbb624cd284a60e4cbde04bc21e6eb82270a
7
+ data.tar.gz: d562c45af8b3f7a099dca7057f54508ecb7ccead617b1fe77debef35e3cb01419137718829c68457128ff5f6ea6e469b00ccb559d9b4758776937ee6d062aebb
data/bin/discover CHANGED
@@ -79,8 +79,7 @@ finder = -> * {
79
79
  )
80
80
  }
81
81
 
82
- case
83
- when args[?s]
82
+ search = -> * {
84
83
  f = nil
85
84
  pattern = pattern.dup
86
85
  args[?n] = Term::ANSIColor.terminal_lines - 1
@@ -112,6 +111,11 @@ when args[?s]
112
111
  else
113
112
  exit 1
114
113
  end
114
+ }
115
+
116
+ case
117
+ when args[?s]
118
+ search.()
115
119
  when args[?E]
116
120
  edit_files *finder.().paths, pick: true
117
121
  when args[?e]
@@ -131,7 +135,8 @@ when pattern.empty? && args[?r]
131
135
  finder.()
132
136
  exit
133
137
  when pattern.empty?
134
- usage
138
+ args[?e] = true
139
+ search.()
135
140
  else
136
141
  puts finder.().search.output
137
142
  end
data/bin/search CHANGED
@@ -7,6 +7,7 @@ require 'tins/xt'
7
7
  include Tins::GO
8
8
  require 'term/ansicolor'
9
9
  include Term::ANSIColor
10
+ require 'tempfile'
10
11
 
11
12
  def convert_ruby_to_vim_regexp(pattern)
12
13
  regexp = pattern.source.dup
@@ -18,14 +19,14 @@ end
18
19
  def read_line(path)
19
20
  filename, lineno = path.source_location
20
21
  line = File.open(filename) do |file|
21
- file.lazy.each_with_index.select { |l, n| n + 1 == lineno }.first&.first
22
+ file.lazy.each_with_index.select { |l, n| n + 1 == lineno }.first&.first
22
23
  end
23
24
  end
24
25
 
25
26
  def replace_line(path, new_line)
26
27
  filename, lineno = path.source_location
27
- File.secure_write filename do |output|
28
- File.open(filename) do |file|
28
+ Tempfile.open do |output|
29
+ File.open(filename, 'r+') do |file|
29
30
  file.each_with_index do |line, n|
30
31
  if n + 1 == lineno
31
32
  output.write new_line
@@ -33,6 +34,11 @@ def replace_line(path, new_line)
33
34
  output.write line
34
35
  end
35
36
  end
37
+ file.rewind
38
+ output.rewind
39
+ output.each do |line|
40
+ file.write line
41
+ end
36
42
  end
37
43
  end
38
44
  end
@@ -51,7 +57,7 @@ def replace_ask(editor, path, pattern, replace, all)
51
57
  replace_line path, new_line
52
58
  break true
53
59
  else
54
- print "Replace? (#{bold(?y)}/n/e/a) "
60
+ print "Replace? (#{bold(?y)}/n/e/a/q) "
55
61
  case answer = STDIN.gets.chomp
56
62
  when ?y, '', ?a
57
63
  new_line = line.gsub(pattern.matcher, replace)
@@ -59,6 +65,8 @@ def replace_ask(editor, path, pattern, replace, all)
59
65
  break answer == ?a
60
66
  when ?n
61
67
  break false
68
+ when ?q
69
+ throw :quit
62
70
  when ?e
63
71
  editor.edit(path.strip)
64
72
  break false
@@ -78,8 +86,10 @@ def edit_files(pattern, paths, pick: false, replace: nil)
78
86
  when replace
79
87
  editor.wait = true
80
88
  all = false
81
- for path in paths
82
- all |= replace_ask editor, path, pattern, replace, all
89
+ catch :quit do
90
+ for path in paths
91
+ all |= replace_ask editor, path, pattern, replace, all
92
+ end
83
93
  end
84
94
  when pick
85
95
  if paths.size > 1
data/lib/utils/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Utils
2
2
  # Utils version
3
- VERSION = '0.34.0'
3
+ VERSION = '0.36.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,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: utils 0.34.0 ruby lib
2
+ # stub: utils 0.36.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "utils".freeze
6
- s.version = "0.34.0"
6
+ s.version = "0.36.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 = "2023-01-05"
11
+ s.date = "2023-06-09"
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 = ["ascii7".freeze, "blameline".freeze, "check-yaml".freeze, "classify".freeze, "create_cstags".freeze, "create_tags".freeze, "discover".freeze, "edit".freeze, "edit_wait".freeze, "enum".freeze, "fix-brew".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, "rd2md".freeze, "search".freeze, "sedit".freeze, "serve".freeze, "ssh-tunnel".freeze, "strip_spaces".freeze, "untest".freeze, "utils-utilsrc".freeze, "vcf2alias".freeze]
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.34.0
4
+ version: 0.36.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: 2023-01-05 00:00:00.000000000 Z
11
+ date: 2023-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar