inplace 1.2.3 → 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 +5 -5
- data/LICENSE +1 -1
- data/README.md +13 -13
- data/Rakefile +7 -0
- data/inplace.gemspec +1 -0
- data/lib/inplace.rb +45 -49
- metadata +8 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ccac19271e8549ee042dd4798133409441b8f07edc3b46590be41243c8422a1b
|
4
|
+
data.tar.gz: d67e327764fefa4f51cdb7136d61e9fe4a39196798104824ea38c15541296aaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cb70cbe001f36c31feaacea51a9c3f1511a1d70f15ef9ca867a36a545446e68426b94222e34baf815a9beca0ab54af41fd219b93dbabc9a6ca58fb475bb9e44
|
7
|
+
data.tar.gz: fbcfd3ff70a729bf4bc1f19740c50a7083a9851a6cce84f28db14ed43e88aeea18f792705fb15ec7727d7ee1336c4b0211ed51d316ad20c9e73186ef9965e1d4
|
data/LICENSE
CHANGED
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
|
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,
|
28
|
-
|
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
|
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 -
|
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
|
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 |
|
187
|
-
|
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
|
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.
|
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]
|
60
|
-
|
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
|
-
|
75
|
-
|
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
|
-
|
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 = {}
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inplace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akinori MUSHA
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies: []
|
13
12
|
description: A command line utility that edits files in-place through given filter
|
14
13
|
commands
|
@@ -19,7 +18,7 @@ executables:
|
|
19
18
|
extensions: []
|
20
19
|
extra_rdoc_files: []
|
21
20
|
files:
|
22
|
-
- .gitignore
|
21
|
+
- ".gitignore"
|
23
22
|
- BSDmakefile
|
24
23
|
- Gemfile
|
25
24
|
- LICENSE
|
@@ -32,26 +31,24 @@ files:
|
|
32
31
|
- man/inplace.1
|
33
32
|
- test/test.sh
|
34
33
|
homepage: https://github.com/knu/inplace
|
35
|
-
licenses:
|
34
|
+
licenses:
|
35
|
+
- 2-clause BSDL
|
36
36
|
metadata: {}
|
37
|
-
post_install_message:
|
38
37
|
rdoc_options: []
|
39
38
|
require_paths:
|
40
39
|
- lib
|
41
40
|
required_ruby_version: !ruby/object:Gem::Requirement
|
42
41
|
requirements:
|
43
|
-
- -
|
42
|
+
- - ">="
|
44
43
|
- !ruby/object:Gem::Version
|
45
44
|
version: '0'
|
46
45
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
46
|
requirements:
|
48
|
-
- -
|
47
|
+
- - ">="
|
49
48
|
- !ruby/object:Gem::Version
|
50
49
|
version: '0'
|
51
50
|
requirements: []
|
52
|
-
|
53
|
-
rubygems_version: 2.0.3
|
54
|
-
signing_key:
|
51
|
+
rubygems_version: 3.7.2
|
55
52
|
specification_version: 4
|
56
53
|
summary: Inplace(1) is a command line utility that edits files in-place through given
|
57
54
|
filter commands. e.g. inplace 'sort' file1 file2 file3
|