inplace 1.2.2 → 1.3.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ccac19271e8549ee042dd4798133409441b8f07edc3b46590be41243c8422a1b
4
+ data.tar.gz: d67e327764fefa4f51cdb7136d61e9fe4a39196798104824ea38c15541296aaa
5
+ SHA512:
6
+ metadata.gz: 6cb70cbe001f36c31feaacea51a9c3f1511a1d70f15ef9ca867a36a545446e68426b94222e34baf815a9beca0ab54af41fd219b93dbabc9a6ca58fb475bb9e44
7
+ data.tar.gz: fbcfd3ff70a729bf4bc1f19740c50a7083a9851a6cce84f28db14ed43e88aeea18f792705fb15ec7727d7ee1336c4b0211ed51d316ad20c9e73186ef9965e1d4
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2004, 2005, 2006, 2007, 2008, 2012 Akinori MUSHA
1
+ Copyright (c) 2004-2023 Akinori MUSHA
2
2
 
3
3
  All rights reserved.
4
4
 
data/README.md CHANGED
@@ -8,9 +8,8 @@ inplace -- edits files in-place through given filter commands
8
8
  ## SYNOPSIS
9
9
 
10
10
  ```
11
- inplace [-DLfinstvz] [-b suffix] -e commandline [[-e commandline] ...]
12
- [file ...]
13
- inplace [-DLfinstvz] [-b suffix] commandline [file ...]
11
+ inplace [-DLfinstvz] [-b SUFFIX]
12
+ [[-e] "COMMANDLINE"] [-E COMMAND ... --] [file ...]
14
13
  ```
15
14
 
16
15
  ## DESCRIPTION
@@ -24,8 +23,8 @@ Inode numbers will change by default, but there is a `-i` option with
24
23
  which given the inode number of each edited file will be preserved.
25
24
 
26
25
  As for filter commands, a single command may be specified as the first
27
- argument to inplace. To pass many filter commands, specify each
28
- followed by the `-e` option.
26
+ argument to inplace. To pass many filter commands, use `-e` or `-E`
27
+ option.
29
28
 
30
29
  There are some cases where inplace does not replace a file, such as
31
30
  when:
@@ -68,6 +67,8 @@ The following command line arguments are supported:
68
67
 
69
68
  * `-e COMMANDLINE`
70
69
  * `--execute COMMANDLINE`
70
+ * `-E COMMAND ... --` / `-E<TERM> COMMAND ... <TERM>`
71
+ * `--execute-args COMMAND ... --` / `--execute-args=<TERM> COMMAND ... <TERM>`
71
72
 
72
73
  Specify a filter command line to run for each file in which the
73
74
  following placeholders can be used:
@@ -103,8 +104,8 @@ The following command line arguments are supported:
103
104
  that file name aware programs can play nicely with it.
104
105
 
105
106
  Instead of specifying a whole command line, you can use a command
106
- alias defined in a configuration file, `~/.inplace`. See the
107
- FILES section for the file format.
107
+ alias defined in a configuration file, `~/.config/inplace/config`
108
+ or `~/.inplace`. See the FILES section for the file format.
108
109
 
109
110
  This option can be specified many times, and they will be executed
110
111
  in sequence. A file is only replaced if all of them succeeds.
@@ -174,24 +175,23 @@ The following command line arguments are supported:
174
175
 
175
176
  * Perform in-place charset conversion and newline code conversion:
176
177
 
177
- inplace -e 'iconv -f EUC-JP -t UTF-8' -e 'perl -pe "s/$/\\r/"'
178
- file1 file2 file3
178
+ inplace -E iconv -f EUC-JP -t UTF-8 -- -E perl -pe 's/$/\r/' -- file1 file2 file3
179
179
 
180
180
  * Process image files taking backup files:
181
181
 
182
- inplace -b.orig 'convert -rotate 270 -resize 50%% %1 %2' *.jpg
182
+ inplace -b.orig -E convert -rotate 270 -resize 50%% %1 %2 -- *.jpg
183
183
 
184
184
  * Perform a mass MP3 tag modification without changing timestamps:
185
185
 
186
- find mp3/Some_Artist -name '*.mp3' -print0 | xargs -0 inplace
187
- -te 'mp3info -a "Some Artist" -g "Progressive Rock" %1'
186
+ find mp3/Some_Artist -name '*.mp3' -print0 | \
187
+ xargs -0 inplace -tE mp3info -a "Some Artist" -g "Progressive Rock" %1 --
188
188
 
189
189
  As you see above, inplace makes a nice combo with find(1) and
190
190
  `xargs(1)`.
191
191
 
192
192
  ## FILES
193
193
 
194
- * `~/.inplace`
194
+ * `~/.config/inplace/config` or `~/.inplace`
195
195
 
196
196
  The configuration file, which syntax is described as follows:
197
197
 
data/Rakefile CHANGED
@@ -6,3 +6,10 @@ task :default => :test
6
6
  task :test do
7
7
  sh 'test/test.sh'
8
8
  end
9
+
10
+ task :tarball do
11
+ gemspec = Bundler::GemHelper.gemspec
12
+ sh <<-'EOF' % [gemspec.name, gemspec.version.to_s]
13
+ git archive --format=tar --prefix=%1$s-%2$s/ v%2$s | bzip2 -9c > %1$s-%2$s.tar.bz2
14
+ EOF
15
+ end
data/inplace.gemspec CHANGED
@@ -10,6 +10,7 @@ Inplace(1) is a command line utility that edits files in-place through
10
10
  given filter commands. e.g. inplace 'sort' file1 file2 file3
11
11
  EOS
12
12
  gem.homepage = "https://github.com/knu/inplace"
13
+ gem.license = "2-clause BSDL"
13
14
 
14
15
  gem.files = `git ls-files`.split("\n")
15
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
data/lib/inplace.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # inplace.rb - edits files in-place through given filter commands
5
5
  #
6
- # Copyright (c) 2004, 2005, 2006, 2007, 2008, 2012 Akinori MUSHA
6
+ # Copyright (c) 2004-2023 Akinori MUSHA
7
7
  #
8
8
  # All rights reserved.
9
9
  #
@@ -29,18 +29,14 @@
29
29
  # SUCH DAMAGE.
30
30
  #
31
31
 
32
- if RUBY_VERSION < "1.8.2"
33
- STDERR.puts "Ruby 1.8.2 or later is required."
34
- exit 255
35
- end
36
-
37
32
  module Inplace
38
- VERSION = "1.2.2"
33
+ VERSION = "1.3.0"
39
34
  end
40
35
 
41
36
  MYNAME = File.basename($0)
42
37
 
43
38
  require "optparse"
39
+ require "shellwords"
44
40
 
45
41
  def main(argv)
46
42
  $uninterruptible = $interrupt = false
@@ -56,8 +52,8 @@ def main(argv)
56
52
  }
57
53
 
58
54
  usage = <<-"EOF"
59
- usage: #{MYNAME} [-Lfinstvz] [-b SUFFIX] COMMANDLINE [file ...]
60
- #{MYNAME} [-Lfinstvz] [-b SUFFIX] [-e COMMANDLINE] [file ...]
55
+ usage: #{MYNAME} [-Lfinstvz] [-b SUFFIX]
56
+ [-e "COMMANDLINE"] [-E COMMAND ... --] [file ...]
61
57
  EOF
62
58
 
63
59
  banner = <<-"EOF"
@@ -71,8 +67,18 @@ Edits files in-place through given filter commands.
71
67
  filters = []
72
68
 
73
69
  $config = Inplace::Config.new
74
- file = File.expand_path("~/.inplace")
75
- $config.load(file) if File.exist?(file)
70
+ [
71
+ File.join(
72
+ ENV.fetch("XDG_CONFIG_HOME") { File.expand_path("~/.config") },
73
+ "inplace/config"
74
+ ),
75
+ File.expand_path("~/.inplace"),
76
+ ].each do |file|
77
+ if File.exist?(file)
78
+ $config.load(file)
79
+ break
80
+ end
81
+ end
76
82
 
77
83
  opts = OptionParser.new(banner, 24) { |opts|
78
84
  nextline = "\n" << opts.summary_indent << " " * opts.summary_width << " "
@@ -113,6 +119,29 @@ Edits files in-place through given filter commands.
113
119
  |s| filters << FileFilter.new($config.expand_alias(s))
114
120
  }
115
121
 
122
+ opts.on("-E", "--execute-args[=TERM]",
123
+ "Run COMMAND with all following arguments until TERM" << nextline <<
124
+ "(default: '--') is encountered." << nextline <<
125
+ "This is similar to -e except it takes a list of" << nextline <<
126
+ "arguments.") { |s|
127
+ term = s || '--'
128
+ args = []
129
+ until (arg = argv.shift) == term
130
+ raise "-E must end with #{term}" if arg.nil?
131
+
132
+ args << arg
133
+ end
134
+ commandline = args.map { |arg|
135
+ case arg
136
+ when /%/
137
+ arg.gsub(/[^A-Za-z0-9_\-.,:+\/@\n%]/, "\\\\\\&").gsub(/\n/, "'\n'")
138
+ else
139
+ arg.shellescape
140
+ end
141
+ }.join(' ')
142
+ filters << FileFilter.new($config.expand_alias(commandline))
143
+ }
144
+
116
145
  opts.on("-f", "--force",
117
146
  "Force editing even if a file is read-only.") {
118
147
  |b| $force = b
@@ -152,7 +181,9 @@ Edits files in-place through given filter commands.
152
181
 
153
182
  setup()
154
183
 
155
- files = opts.order(*argv)
184
+ argv = argv.dup
185
+ opts.order!(argv)
186
+ files = argv
156
187
 
157
188
  if filters.empty? && !files.empty?
158
189
  filters << FileFilter.new($config.expand_alias(files.shift))
@@ -222,6 +253,8 @@ require 'pathname'
222
253
 
223
254
  class FileFilter
224
255
  def initialize(template)
256
+ raise ArgumentError, "empty command" if template.empty?
257
+
225
258
  @formatter = Formatter.new(template)
226
259
  end
227
260
 
@@ -466,43 +499,6 @@ class FileFilter
466
499
  end
467
500
  end
468
501
 
469
- if RUBY_VERSION >= "1.8.7"
470
- require 'shellwords'
471
- else
472
- class String
473
- def shellescape
474
- # An empty argument will be skipped, so return empty quotes.
475
- return "''" if empty?
476
-
477
- str = dup
478
-
479
- # Process as a single byte sequence because not all shell
480
- # implementations are multibyte aware.
481
- str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/n, "\\\\\\1")
482
-
483
- # A LF cannot be escaped with a backslash because a backslash + LF
484
- # combo is regarded as line continuation and simply ignored.
485
- str.gsub!(/\n/, "'\n'")
486
-
487
- return str
488
- end
489
- end
490
-
491
- class Tempfile
492
- alias orig_make_tmpname make_tmpname
493
-
494
- def make_tmpname(basename, n)
495
- case basename
496
- when Array
497
- prefix, suffix = *basename
498
- make_tmpname(prefix, n) + suffix
499
- else
500
- orig_make_tmpname(basename, n).tr('.', '-')
501
- end
502
- end
503
- end
504
- end
505
-
506
502
  class Inplace::Config
507
503
  def initialize
508
504
  @alias = {}
data/man/inplace.1 CHANGED
@@ -1,7 +1,7 @@
1
1
  .\" $Idaemons: /home/cvs/inplace/inplace.1,v 1.8 2004/04/21 13:25:51 knu Exp $
2
2
  .\" $Id$
3
3
  .\"
4
- .Dd April 7, 2004
4
+ .Dd November 22, 2012
5
5
  .Dt INPLACE 1
6
6
  .Os FreeBSD
7
7
  .Sh NAME
@@ -251,4 +251,17 @@ is specified, they will not be used.
251
251
  .Sh AUTHORS
252
252
  .An Akinori MUSHA Aq knu@iDaemons.org
253
253
  .Sh BUGS
254
- There may always be some bugs. Use at your own risk.
254
+ .Nm
255
+ cannot always preserve timestamps in full precision depending on the
256
+ ruby interpreter and the platform that
257
+ .Nm
258
+ runs on, that is, ruby 1.9 and later supports timestamps in
259
+ nanoseconds but setting file timestamps in nanosecond precision is
260
+ only possible if the platform supports
261
+ .Xr utimensat 2 .
262
+ .Pp
263
+ So, a problem can arise if the file system supports nanoseconds, like
264
+ ext4 and ZFS, but the platform does not have the system call to set
265
+ timestamps in nanoseconds, like Linux < 2.6.22, glibc < 2.6 and
266
+ .Fx ,
267
+ that the sub-microsecond part of a timestamp cannot be preserved.
data/test/test.sh CHANGED
@@ -97,12 +97,12 @@ cmp_file () {
97
97
  }
98
98
 
99
99
  cmp_time () {
100
- # Since Ruby's File.stat() does not obtain nanosec for the moment,
101
- # inplace(1) cannot preserve nanosec values and test(1)'s strict
102
- # nanosec-wise check does not pass..
100
+ # Use ruby to compare timestamps ignoring a sub-microsecond
101
+ # difference.
102
+
103
103
  #test ! "$1" -nt "$2" -a ! "$2" -nt "$1"
104
104
 
105
- if $ruby -e 'File.mtime(ARGV[0]) == File.mtime(ARGV[1]) or exit 1' "$1" "$2"; then
105
+ if $ruby -e 'exit !!ARGV.map{|f|m=File.mtime(f);m.to_a<<m.usec}.uniq!' "$1" "$2"; then
106
106
  debug "mtime($1) == mtime($2)"
107
107
  return 0
108
108
  else
metadata CHANGED
@@ -1,34 +1,24 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: inplace
3
- version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease:
6
- segments:
7
- - 1
8
- - 2
9
- - 2
10
- version: 1.2.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Akinori MUSHA
14
- autorequire:
15
8
  bindir: bin
16
9
  cert_chain: []
17
-
18
- date: 2012-03-05 00:00:00 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
19
11
  dependencies: []
20
-
21
- description: A command line utility that edits files in-place through given filter commands
22
- email:
12
+ description: A command line utility that edits files in-place through given filter
13
+ commands
14
+ email:
23
15
  - knu@idaemons.org
24
- executables:
16
+ executables:
25
17
  - inplace
26
18
  extensions: []
27
-
28
19
  extra_rdoc_files: []
29
-
30
- files:
31
- - .gitignore
20
+ files:
21
+ - ".gitignore"
32
22
  - BSDmakefile
33
23
  - Gemfile
34
24
  - LICENSE
@@ -41,37 +31,26 @@ files:
41
31
  - man/inplace.1
42
32
  - test/test.sh
43
33
  homepage: https://github.com/knu/inplace
44
- licenses: []
45
-
46
- post_install_message:
34
+ licenses:
35
+ - 2-clause BSDL
36
+ metadata: {}
47
37
  rdoc_options: []
48
-
49
- require_paths:
38
+ require_paths:
50
39
  - lib
51
- required_ruby_version: !ruby/object:Gem::Requirement
52
- none: false
53
- requirements:
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
54
42
  - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
60
- required_rubygems_version: !ruby/object:Gem::Requirement
61
- none: false
62
- requirements:
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
63
47
  - - ">="
64
- - !ruby/object:Gem::Version
65
- hash: 3
66
- segments:
67
- - 0
68
- version: "0"
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
69
50
  requirements: []
70
-
71
- rubyforge_project:
72
- rubygems_version: 1.8.15
73
- signing_key:
74
- specification_version: 3
75
- summary: Inplace(1) is a command line utility that edits files in-place through given filter commands. e.g. inplace 'sort' file1 file2 file3
76
- test_files:
51
+ rubygems_version: 3.7.2
52
+ specification_version: 4
53
+ summary: Inplace(1) is a command line utility that edits files in-place through given
54
+ filter commands. e.g. inplace 'sort' file1 file2 file3
55
+ test_files:
77
56
  - test/test.sh