utils 0.94.0 → 0.95.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e75e4da900a5682f8be3d521d422a48b201f1ba9868468f703b420d344860e8
4
- data.tar.gz: 2f1317551005fd0e0c413a76f790dcfd670c60124a1c88376b4b8d60001861b5
3
+ metadata.gz: dd3330bad863906079106f503caa40f83af5dd978e5c4cbec9561cfbf22228b8
4
+ data.tar.gz: 1081b4d918807345b36faa44d13b1c5ec287bdaf8156edfa3090ec909c3570a3
5
5
  SHA512:
6
- metadata.gz: 7bd6708c73311146fab0a0f14e4dfb5b470b958bee9911630c12cc40468ff359be46680a53f12c48310f058680d89d5693ab7040ff91c1dd778ca6f618f305b5
7
- data.tar.gz: 6093657c875f1f276b3e8b95b1f799521200baca5d29568c06e032059b5a5888c01c333028e63adac91d8eeb75a05fba5adf2d2c7e73bf171e4cb53048515480
6
+ metadata.gz: 2fcaa85ef0d3a75b97d6c019c6ffd824e519505204056760956df512e6a85dd41a44787a9a665331c21ff5477cdebbc6c97607749fcabc7d404bcc18654e7b15
7
+ data.tar.gz: 2ed4678d7c0b12d96f3d0099ae3563d553e9f571b3e1c6ee12d8d910b22cd0357795fc42ebf3383f34323c00f84c256984f716e25dda4eec91c21ac0b1f8a434
data/README.md CHANGED
@@ -52,8 +52,7 @@ gem install utils
52
52
  ### 🔍 Searching
53
53
 
54
54
  - **`blameline`** - Show git blame line for a file and line number
55
- - **`create_cstags`** - Create cscope tags file for current directory
56
- - **`create_tags`** - Create ctags tags file for current directory
55
+ - **`code_indexer`** - Create ctags/cscope tags file for current directory
57
56
  - **`discover`** - Find files with specific content patterns
58
57
  - **`git-versions`** - Show git versions of files and directories
59
58
  - **`long_lines`** - Finds long lines with author attribution
data/bin/code_indexer CHANGED
@@ -4,11 +4,22 @@ require 'utils'
4
4
  config = Utils::ConfigFile.new
5
5
  config.configure_from_paths
6
6
 
7
+ only_format = ARGV.shift
8
+
7
9
  config.code_indexer.formats.each do |format, output|
10
+ if only_format
11
+ format == only_format or next
12
+ end
8
13
  paths = config.code_indexer.paths.grep_v(/Resolving dependencies/)
9
14
  puts "Indexing code for #{format}…"
10
- cmd = [ 'starscope', '-e', format, '-f', output, '--no-read' ]
11
- config.code_indexer.verbose and cmd << '--verbose'
15
+ case format
16
+ when 'ctags'
17
+ cmd = [ 'ctags', '-f', output, '--exclude=pkg', '-R' ]
18
+ config.code_indexer.verbose and cmd << '--verbose'
19
+ when 'cscope'
20
+ cmd = [ 'starscope', '-e', format, '-f', output, '--no-read' ]
21
+ config.code_indexer.verbose and cmd << '--verbose'
22
+ end
12
23
  cmd.push(*paths)
13
24
  system(*cmd)
14
25
  puts "Done."
data/bin/on_change CHANGED
@@ -1,53 +1,118 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # Monitor file for changes and execute command when modified
3
+ # Monitor a set of files (specified by glob patterns) for modifications.
4
+ # When any watched file changes, run an arbitrary shell command,
5
+ # optionally inserting the full path of that file via the placeholder %f.
4
6
  #
5
7
  # Usage:
6
- # on_change filename [command...] # Watch file and run command on changes
8
+ # ./on_change [OPTS] [COMMAND]
7
9
  #
8
- # This script monitors a file for modifications and executes a specified
9
- # command whenever the file is changed. It can be used for auto-reloading,
10
- # rebuilding, or triggering actions when source files are updated.
10
+ # Options:
11
+ # -i <glob> Glob pattern(s) of files to watch. Can be repeated
12
+ # e.g., `-i 'lib/**/*.rb' -i bin/*`.
13
+ # -d <sec> Sleep interval (seconds) when no changes are detected.
14
+ # Must be a positive integer; defaults to 1 if omitted or <=0.
15
+ # -h Show this help message and exit.
11
16
  #
12
- # If no command is provided, 'true' is executed by default.
17
+ # If [COMMAND] is not supplied the script defaults to running `true`.
13
18
  #
14
- # Special replacement:
15
- # %f in command will be replaced with the filename being monitored
19
+ # Command placeholder:
20
+ # The string `%f` inside COMMAND will be replaced by the full path of
21
+ # each file that changed. Example:
22
+ # ./on_change -i 'lib/**/*.rb' echo '%f has been modified'
16
23
  #
17
- # Examples:
18
- # on_change Gemfile bundle install
19
- # on_change tests/utils_test.rb ruby -I lib:tests %f
24
+ # It prints each executed command (for debugging) before streaming its
25
+ # output to STDOUT.
26
+
27
+ require 'set'
28
+ require 'tins/go'
29
+ include Tins::GO
30
+ require 'shellwords'
20
31
 
21
32
  # The execute method runs a command by processing its arguments and displaying
22
33
  # the output.
23
34
  #
24
35
  # @param args [ Array ] the command arguments to be executed
25
36
  def execute(*args)
26
- cmd = args.map(&:inspect) * ' '
27
- puts "Executing: #{cmd}"
37
+ cmd = Shellwords.join(args)
38
+ puts "Executing: #{cmd.inspect}"
28
39
  IO.popen(cmd, 'r') do |io|
29
40
  io.each { |l| puts l }
30
41
  end
31
42
  end
32
43
 
44
+ # Computes a set of file paths based on glob patterns specified in the global
45
+ # $opts[?i] option. It iterates over each pattern, expands it with Dir.glob,
46
+ # and merges the results into a Set to eliminate duplicates.
47
+ #
48
+ # @return [Set<String>] a set containing the unique file paths matched by the
49
+ # provided glob patterns
50
+ def compute_files
51
+ files = Set[]
52
+ $opts[?i].to_a.each do |glob|
53
+ files.merge Dir.glob(glob)
54
+ end
55
+ files
56
+ end
57
+
58
+ # The usage method displays a help message explaining command‑line options and
59
+ # exits the program with the supplied return code.
60
+ #
61
+ # @param rc [ Integer ] the exit status to use when terminating the process
62
+ def usage(rc)
63
+ puts <<~EOT
64
+ Usage: #{File.basename($0)} [OPTS] [COMMAND]
65
+
66
+ Options are
67
+
68
+ -i <glob> Glob pattern(s) of files to watch.
69
+ The option may be repeated; all matching paths will be monitored.
70
+ -d <sec> Sleep interval (in seconds) when no file changes are detected.
71
+ Defaults to 1 second if omitted or set to a non‑positive value.
72
+ -h Show this help message and exit.
73
+
74
+ If [COMMAND] is not supplied the script defaults to running `true`.
75
+
76
+ The command may contain the placeholder `%f`, which will be replaced by
77
+ the full path of each file that changed. For example:
78
+
79
+ #{File.basename($0)} -i 'lib/**/*.rb' -i 'bin/*' echo %f has been modified
80
+
81
+ EOT
82
+ exit rc
83
+ end
84
+
85
+ $opts = go 'i:d:h'
86
+
87
+ $opts[?h] and usage(0)
88
+
33
89
  argv = ARGV.dup
34
- filename = argv.shift or fail "require a filename as first argument"
35
90
  argv.empty? and argv << 'true'
36
- argv.map! { |a| a == '%f' ? filename : a }
37
- warn "Observing #{filename.inspect} for changes now and execute #{argv.inspect}."
38
- old_mtime = nil
91
+
92
+ files = compute_files
93
+ files.empty? and fail 'Require files to watch'
94
+
95
+ old_mtimes = {}
96
+ files.each do |filename|
97
+ mtime = File.mtime(filename)
98
+ old_mtimes[filename] = mtime
99
+ end
100
+
39
101
  loop do
40
- begin
41
- mtime = File.mtime(filename)
42
- if old_mtime.nil? || mtime > old_mtime
43
- execute(*argv)
44
- else
45
- sleep 0.1
102
+ files = compute_files
103
+
104
+ files.each do |filename|
105
+ begin
106
+ mtime = File.mtime(filename)
107
+ if !old_mtimes.key?(filename) || mtime > old_mtimes[filename]
108
+ execute(*argv.map { _1 == '%f' ? filename : _1 })
109
+ end
110
+ old_mtimes[filename] = mtime
111
+ rescue Interrupt
112
+ exit 0
113
+ rescue Errno::ENOENT
114
+ old_mtimes.delete(filename)
46
115
  end
47
- rescue Interrupt
48
- exit 1
49
- rescue Errno::ENOENT
50
- ensure
51
- old_mtime = mtime
52
116
  end
117
+ sleep $opts[?d].to_i.clamp(1..)
53
118
  end
data/lib/utils/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Utils
2
2
  # Utils version
3
- VERSION = '0.94.0'
3
+ VERSION = '0.95.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,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: utils 0.94.0 ruby lib
2
+ # stub: utils 0.95.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "utils".freeze
6
- s.version = "0.94.0".freeze
6
+ s.version = "0.95.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]
@@ -17,13 +17,13 @@ Gem::Specification.new do |s|
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.4".freeze
20
+ s.rubygems_version = "4.0.3".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.8".freeze])
26
+ s.add_development_dependency(%q<gem_hadar>.freeze, [">= 2.17.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])
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.94.0
4
+ version: 0.95.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -13,16 +13,16 @@ dependencies:
13
13
  name: gem_hadar
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - "~>"
16
+ - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: '2.8'
18
+ version: 2.17.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.8'
25
+ version: 2.17.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: test-unit
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -430,7 +430,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
430
430
  - !ruby/object:Gem::Version
431
431
  version: '0'
432
432
  requirements: []
433
- rubygems_version: 4.0.4
433
+ rubygems_version: 4.0.3
434
434
  specification_version: 4
435
435
  summary: Some useful command line utilities
436
436
  test_files: