renamr 1.0.15 → 1.0.17
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 +4 -4
- data/LICENSE +1 -1
- data/README.adoc +25 -24
- data/bin/renamr +3 -3
- data/lib/renamr/action.rb +4 -4
- data/lib/renamr/ascii_validator.rb +4 -4
- data/lib/renamr/auto_localization.rb +4 -4
- data/lib/renamr/char.rb +3 -3
- data/lib/renamr/configurator.rb +27 -17
- data/lib/renamr/date.rb +4 -4
- data/lib/renamr/downcase.rb +3 -3
- data/lib/renamr/factory.rb +6 -6
- data/lib/renamr/manual_localization.rb +13 -13
- data/lib/renamr/omit.rb +3 -3
- data/lib/renamr/point.rb +3 -3
- data/lib/renamr/prepend.rb +4 -4
- data/lib/renamr/prepend_date.rb +3 -3
- data/lib/renamr/remove.rb +7 -8
- data/lib/renamr/renamer.rb +11 -9
- data/lib/renamr/reporter.rb +4 -3
- data/lib/renamr/rutoen.rb +2 -2
- data/lib/renamr/substitute.rb +4 -4
- data/lib/renamr/timer.rb +36 -0
- data/lib/renamr/trim.rb +5 -4
- data/lib/renamr/truncate.rb +5 -4
- data/lib/renamr/utils.rb +12 -33
- data/lib/renamr/version.rb +4 -4
- data/lib/renamr.rb +2 -2
- metadata +74 -20
- data/.github/dependabot.yml +0 -13
- data/.github/workflows/actionlint.yml +0 -25
- data/.github/workflows/rake.yml +0 -27
- data/.github/workflows/rubocop.yml +0 -34
- data/.github/workflows/test.yml +0 -20
- data/.gitignore +0 -7
- data/.travis.yml +0 -14
- data/Gemfile +0 -16
- data/LICENSES/0BSD.txt +0 -5
- data/REUSE.toml +0 -11
- data/Rakefile +0 -13
- data/renamr.gemspec +0 -28
- data/test/test_char.rb +0 -19
- data/test/test_date.rb +0 -32
- data/test/test_trim.rb +0 -22
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7bdc397de28bfad991bced9b577d5f69b510052389ed06af3044490fac938336
|
|
4
|
+
data.tar.gz: 56e4d20a103f4c330ba2ed9767d4ced07076b0eaf602a14a89ee3c25af7d0f26
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 91bd8b832ccd58c174d91825a2690641ec21b8b408ab9da3ee16c3625530748373520aa5417d16ca707bcdf8a7f552cfdfd8e19c1e843d44f0492a8be155d761
|
|
7
|
+
data.tar.gz: 3f2e603f6ae91a1d3963fb0386c9c9b8f50c8fd12e109b675e6375aa70fd407440ca0df56c17bc3c347b074a94fe455c0445fb4fdbcda10d30600a3f142bd8d5
|
data/LICENSE
CHANGED
data/README.adoc
CHANGED
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
:img-rake: https://github.com/rdavid/renamr/actions/workflows/rake.yml/badge.svg
|
|
9
9
|
:img-rubocop: https://github.com/rdavid/renamr/actions/workflows/rubocop.yml/badge.svg
|
|
10
10
|
:img-style: https://img.shields.io/badge/code_style-rubocop-brightgreen.svg
|
|
11
|
-
:img-test: https://github.com/rdavid/renamr/actions/workflows/test.yml/badge.svg
|
|
12
11
|
:url-cv: http://cv.rabkin.co.il
|
|
13
12
|
:url-gem: https://badge.fury.io/rb/renamr
|
|
14
13
|
:url-hoc: https://hitsofcode.com/view/github/rdavid/renamr?branch=master
|
|
@@ -18,7 +17,6 @@
|
|
|
18
17
|
:url-rubocop: https://github.com/rdavid/renamr/actions/workflows/rubocop.yml
|
|
19
18
|
:url-ruby: https://www.ruby-lang.org/en/documentation/installation
|
|
20
19
|
:url-style: https://github.com/rubocop/rubocop
|
|
21
|
-
:url-test: https://github.com/rdavid/renamr/actions/workflows/test.yml
|
|
22
20
|
:url-vale: https://vale.sh
|
|
23
21
|
:url-yamllint: https://github.com/adrienverge/yamllint
|
|
24
22
|
|
|
@@ -28,7 +26,6 @@ image:{img-rake}[rake,link={url-rake}]
|
|
|
28
26
|
image:{img-rubocop}[rubocop,link={url-rubocop}]
|
|
29
27
|
image:{img-gem}[gem version,link={url-gem}]
|
|
30
28
|
image:{img-style}[code style,link={url-style}]
|
|
31
|
-
image:{img-test}[test,link={url-test}]
|
|
32
29
|
image:{img-hoc}[hits of code,link={url-hoc}]
|
|
33
30
|
image:{img-license}[license,link={url-license}]
|
|
34
31
|
|
|
@@ -36,16 +33,17 @@ toc::[]
|
|
|
36
33
|
|
|
37
34
|
== About
|
|
38
35
|
|
|
39
|
-
`renamr`
|
|
36
|
+
`renamr` normalizes file and directory names.
|
|
37
|
+
It rewrites them with lowercase English letters, digits, and hyphens in place
|
|
38
|
+
of spaces and other symbols.
|
|
40
39
|
|
|
41
40
|
== Installation
|
|
42
|
-
The tool
|
|
43
|
-
|
|
44
|
-
It is packaged as a
|
|
45
|
-
If
|
|
46
|
-
{url-ruby}[Installing Ruby].
|
|
41
|
+
The tool runs on macOS, GNU/Linux, and other Unix-like operating systems, as
|
|
42
|
+
well as Windows.
|
|
43
|
+
It is packaged as a Ruby gem and requires Ruby 3.2 or later.
|
|
44
|
+
If your platform lacks a suitable Ruby, see {url-ruby}[Installing Ruby].
|
|
47
45
|
|
|
48
|
-
|
|
46
|
+
Install the gem with:
|
|
49
47
|
|
|
50
48
|
[,sh]
|
|
51
49
|
----
|
|
@@ -54,7 +52,7 @@ gem install renamr
|
|
|
54
52
|
|
|
55
53
|
== Updating
|
|
56
54
|
|
|
57
|
-
|
|
55
|
+
Update the gem with:
|
|
58
56
|
|
|
59
57
|
[,sh]
|
|
60
58
|
----
|
|
@@ -66,17 +64,17 @@ gem update renamr
|
|
|
66
64
|
[,sh]
|
|
67
65
|
----
|
|
68
66
|
renamr [options]
|
|
69
|
-
-a, --act
|
|
70
|
-
-
|
|
71
|
-
-
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
75
|
-
-
|
|
76
|
-
-
|
|
77
|
-
-
|
|
78
|
-
-
|
|
79
|
-
-
|
|
67
|
+
-a, --act Performs actual renaming.
|
|
68
|
+
-c, --cut pos,len Removes len characters starting at pos.
|
|
69
|
+
-d, --dir dir Directory to process.
|
|
70
|
+
-l, --lim Limits file name length.
|
|
71
|
+
-m, --mod Prepends file modification time.
|
|
72
|
+
-p, --prepend str,beg Prepends a string.
|
|
73
|
+
-r, --rec Processes directories recursively.
|
|
74
|
+
-s, --src src String to replace.
|
|
75
|
+
-t, --dst dst Replacement string.
|
|
76
|
+
-v, --version Shows the version.
|
|
77
|
+
-w, --wid wid Output table width.
|
|
80
78
|
----
|
|
81
79
|
|
|
82
80
|
== Example
|
|
@@ -86,9 +84,12 @@ renamr [options]
|
|
|
86
84
|
renamr -d <source>
|
|
87
85
|
----
|
|
88
86
|
|
|
89
|
-
|
|
87
|
+
This previews new names for all files in `source` using the default character
|
|
88
|
+
set: the 26 English letters, 10 digits, and hyphens in place of spaces and
|
|
89
|
+
other symbols.
|
|
90
|
+
Adding `-a` performs the actual renaming.
|
|
90
91
|
|
|
91
92
|
== License
|
|
92
93
|
|
|
93
|
-
`renamr` is copyright {url-cv}[David Rabkin] and available under
|
|
94
|
+
`renamr` is copyright {url-cv}[David Rabkin] and is available under the
|
|
94
95
|
{url-license}[Zero-Clause BSD license].
|
data/bin/renamr
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
-
# vi:
|
|
5
|
-
# SPDX-FileCopyrightText: 2018-
|
|
4
|
+
# vi: et lbr sw=2 ts=2 tw=79 wrap
|
|
5
|
+
# SPDX-FileCopyrightText: 2018-2026 David Rabkin
|
|
6
6
|
# SPDX-License-Identifier: 0BSD
|
|
7
7
|
#
|
|
8
|
-
#
|
|
8
|
+
# Renames files in a directory using configured rules.
|
|
9
9
|
|
|
10
10
|
require_relative '../lib/renamr'
|
|
11
11
|
|
data/lib/renamr/action.rb
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# vi:
|
|
4
|
-
# SPDX-FileCopyrightText: 2018-
|
|
3
|
+
# vi: et lbr sw=2 ts=2 tw=79 wrap
|
|
4
|
+
# SPDX-FileCopyrightText: 2018-2026 David Rabkin
|
|
5
5
|
# SPDX-License-Identifier: 0BSD
|
|
6
6
|
|
|
7
7
|
module Renamr
|
|
8
|
-
#
|
|
8
|
+
# Defines the interface for action implementations.
|
|
9
9
|
class Action
|
|
10
10
|
def do(src)
|
|
11
|
-
raise "
|
|
11
|
+
raise "Action.do must be overridden, called with #{src}."
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def set(src) end
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# vi:
|
|
4
|
-
# SPDX-FileCopyrightText: 2018-
|
|
3
|
+
# vi: et lbr sw=2 ts=2 tw=79 wrap
|
|
4
|
+
# SPDX-FileCopyrightText: 2018-2026 David Rabkin
|
|
5
5
|
# SPDX-License-Identifier: 0BSD
|
|
6
6
|
|
|
7
7
|
require_relative 'action'
|
|
8
8
|
|
|
9
9
|
module Renamr
|
|
10
|
-
# Checks
|
|
10
|
+
# Checks whether the resulting string contains only ASCII characters.
|
|
11
11
|
class ASCIIValidatorAction < Action
|
|
12
12
|
def do(src)
|
|
13
13
|
ascii = src.chars.select(&:ascii_only?).join
|
|
14
|
-
raise "String #{src}
|
|
14
|
+
raise "String #{src} contains non-ASCII characters." if src != ascii
|
|
15
15
|
|
|
16
16
|
src
|
|
17
17
|
end
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# vi:
|
|
4
|
-
# SPDX-FileCopyrightText: 2018-
|
|
3
|
+
# vi: et lbr sw=2 ts=2 tw=79 wrap
|
|
4
|
+
# SPDX-FileCopyrightText: 2018-2026 David Rabkin
|
|
5
5
|
# SPDX-License-Identifier: 0BSD
|
|
6
6
|
|
|
7
7
|
require 'i18n'
|
|
8
8
|
require_relative 'action'
|
|
9
9
|
|
|
10
10
|
module Renamr
|
|
11
|
-
#
|
|
11
|
+
# Performs automatic localization using I18n transliteration.
|
|
12
12
|
class AutoLocalizationAction < Action
|
|
13
13
|
def initialize
|
|
14
|
-
super
|
|
14
|
+
super
|
|
15
15
|
I18n.config.available_locales = :en
|
|
16
16
|
end
|
|
17
17
|
|
data/lib/renamr/char.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# vi:
|
|
4
|
-
# SPDX-FileCopyrightText: 2018-
|
|
3
|
+
# vi: et lbr sw=2 ts=2 tw=79 wrap
|
|
4
|
+
# SPDX-FileCopyrightText: 2018-2026 David Rabkin
|
|
5
5
|
# SPDX-License-Identifier: 0BSD
|
|
6
6
|
|
|
7
7
|
require_relative 'action'
|
|
8
8
|
|
|
9
9
|
module Renamr
|
|
10
|
-
#
|
|
10
|
+
# Replaces special symbols with hyphens, except `.`, `&`, and `$`.
|
|
11
11
|
class CharAction < Action
|
|
12
12
|
SYM = ' (){},~–\'![]_#@=„“”"`—+‘’;·‡«»%…'.chars.to_set.freeze
|
|
13
13
|
|
data/lib/renamr/configurator.rb
CHANGED
|
@@ -1,57 +1,66 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# vi:
|
|
4
|
-
# SPDX-FileCopyrightText: 2018-
|
|
3
|
+
# vi: et lbr sw=2 ts=2 tw=79 wrap
|
|
4
|
+
# SPDX-FileCopyrightText: 2018-2026 David Rabkin
|
|
5
5
|
# SPDX-License-Identifier: 0BSD
|
|
6
6
|
|
|
7
7
|
require 'optparse'
|
|
8
8
|
|
|
9
9
|
module Renamr
|
|
10
|
-
#
|
|
10
|
+
# Parses and validates command-line options.
|
|
11
11
|
class Configurator
|
|
12
12
|
DIC = [
|
|
13
|
-
['-a', '--act', '
|
|
14
|
-
['-
|
|
15
|
-
['-l', '--lim', 'Limits name length.',
|
|
16
|
-
['-m', '--mod', 'Prepends modification time.',
|
|
17
|
-
['-
|
|
18
|
-
['-s', '--src src', '
|
|
19
|
-
['-t', '--dst dst', '
|
|
20
|
-
['-w', '--wid wid', '
|
|
13
|
+
['-a', '--act', 'Performs actual renaming.', :act],
|
|
14
|
+
['-d', '--dir dir', 'Directory to process.', :dir],
|
|
15
|
+
['-l', '--lim', 'Limits file name length.', :lim],
|
|
16
|
+
['-m', '--mod', 'Prepends file modification time.', :mod],
|
|
17
|
+
['-r', '--rec', 'Processes directories recursively.', :rec],
|
|
18
|
+
['-s', '--src src', 'String to replace.', :src],
|
|
19
|
+
['-t', '--dst dst', 'Replacement string.', :dst],
|
|
20
|
+
['-w', '--wid wid', 'Output table width.', :wid]
|
|
21
21
|
].freeze
|
|
22
22
|
|
|
23
|
+
def add_simple(opt, key)
|
|
24
|
+
f, p, d = DIC.find { |_, _, _, k| k == key }
|
|
25
|
+
opt.on(f, p, d) { |i| @options[key] = i }
|
|
26
|
+
end
|
|
27
|
+
|
|
23
28
|
def add_cut(opt)
|
|
24
|
-
|
|
29
|
+
msg = 'Removes len characters starting at pos.'
|
|
30
|
+
opt.on('-c', '--cut pos,len', Array, msg) do |l|
|
|
25
31
|
@options[:pos] = l[0]
|
|
26
32
|
@options[:len] = l[1]
|
|
27
33
|
end
|
|
28
34
|
end
|
|
29
35
|
|
|
30
36
|
def add_prepend(opt)
|
|
31
|
-
opt.on('-p', '--prepend str,beg', Array, '
|
|
37
|
+
opt.on('-p', '--prepend str,beg', Array, 'Prepends a string.') do |l|
|
|
32
38
|
@options[:pre] = l[0]
|
|
33
39
|
@options[:beg] = l[1].nil? ? 0 : l[1].to_i
|
|
34
40
|
end
|
|
35
41
|
end
|
|
36
42
|
|
|
37
43
|
def add_version(opt)
|
|
38
|
-
opt.on('-v', '--version', '
|
|
44
|
+
opt.on('-v', '--version', 'Shows the version.') do
|
|
39
45
|
puts "#{File.basename($PROGRAM_NAME)} #{VERSION} #{DATE}"
|
|
40
46
|
exit
|
|
41
47
|
end
|
|
42
48
|
end
|
|
43
49
|
|
|
44
50
|
def add(opt)
|
|
51
|
+
add_simple(opt, :act)
|
|
45
52
|
add_cut(opt)
|
|
53
|
+
%i[dir lim mod].each { |k| add_simple(opt, k) }
|
|
46
54
|
add_prepend(opt)
|
|
55
|
+
%i[rec src dst].each { |k| add_simple(opt, k) }
|
|
47
56
|
add_version(opt)
|
|
57
|
+
add_simple(opt, :wid)
|
|
48
58
|
end
|
|
49
59
|
|
|
50
60
|
def initialize
|
|
51
61
|
@options = {}
|
|
52
62
|
OptionParser.new do |o|
|
|
53
63
|
o.banner = "Usage: #{File.basename($PROGRAM_NAME)} [options]."
|
|
54
|
-
DIC.each { |f, p, d, k| o.on(f, p, d) { |i| @options[k] = i } }
|
|
55
64
|
add(o)
|
|
56
65
|
end.parse!
|
|
57
66
|
validate
|
|
@@ -65,7 +74,7 @@ module Renamr
|
|
|
65
74
|
|
|
66
75
|
@options[:dir] = File.expand_path(dir)
|
|
67
76
|
end
|
|
68
|
-
raise "
|
|
77
|
+
raise "Table width must be at least 15 characters: #{wid}." if wid < 15
|
|
69
78
|
end
|
|
70
79
|
|
|
71
80
|
def act?
|
|
@@ -114,7 +123,8 @@ module Renamr
|
|
|
114
123
|
|
|
115
124
|
def wid
|
|
116
125
|
if @options[:wid].nil?
|
|
117
|
-
|
|
126
|
+
|
|
127
|
+
# Reads the current terminal width.
|
|
118
128
|
wid = `tput cols`
|
|
119
129
|
wid.to_s.empty? ? 79 : wid.to_i
|
|
120
130
|
else
|
data/lib/renamr/date.rb
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# vi:
|
|
4
|
-
# SPDX-FileCopyrightText: 2018-
|
|
3
|
+
# vi: et lbr sw=2 ts=2 tw=79 wrap
|
|
4
|
+
# SPDX-FileCopyrightText: 2018-2026 David Rabkin
|
|
5
5
|
# SPDX-License-Identifier: 0BSD
|
|
6
6
|
|
|
7
7
|
require 'date'
|
|
8
8
|
require_relative 'action'
|
|
9
9
|
|
|
10
10
|
module Renamr
|
|
11
|
-
# Replaces
|
|
11
|
+
# Replaces valid dates (for example, 2020-11-02 or 02-11-2020) with 20201102.
|
|
12
12
|
class DateAction < Action
|
|
13
13
|
REG = /(\d+)-(\d+)-(\d+)/
|
|
14
14
|
PAT = ['%m-%d-%Y', '%d-%m-%Y', '%Y-%m-%d', '%Y-%d-%m'].freeze
|
|
@@ -25,7 +25,7 @@ module Renamr
|
|
|
25
25
|
PAT.each do |pat|
|
|
26
26
|
return Date.strptime(sub, pat)
|
|
27
27
|
rescue ArgumentError
|
|
28
|
-
#
|
|
28
|
+
# Tries the next date pattern.
|
|
29
29
|
end
|
|
30
30
|
nil
|
|
31
31
|
end
|
data/lib/renamr/downcase.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# vi:
|
|
4
|
-
# SPDX-FileCopyrightText: 2018-
|
|
3
|
+
# vi: et lbr sw=2 ts=2 tw=79 wrap
|
|
4
|
+
# SPDX-FileCopyrightText: 2018-2026 David Rabkin
|
|
5
5
|
# SPDX-License-Identifier: 0BSD
|
|
6
6
|
|
|
7
7
|
require_relative 'action'
|
|
8
8
|
|
|
9
9
|
module Renamr
|
|
10
|
-
#
|
|
10
|
+
# Converts names to lowercase.
|
|
11
11
|
class DowncaseAction < Action
|
|
12
12
|
def do(src)
|
|
13
13
|
src.downcase
|
data/lib/renamr/factory.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# vi:
|
|
4
|
-
# SPDX-FileCopyrightText: 2018-
|
|
3
|
+
# vi: et lbr sw=2 ts=2 tw=79 wrap
|
|
4
|
+
# SPDX-FileCopyrightText: 2018-2026 David Rabkin
|
|
5
5
|
# SPDX-License-Identifier: 0BSD
|
|
6
6
|
|
|
7
7
|
require_relative 'ascii_validator'
|
|
@@ -21,15 +21,15 @@ require_relative 'trim'
|
|
|
21
21
|
require_relative 'truncate'
|
|
22
22
|
|
|
23
23
|
module Renamr
|
|
24
|
-
#
|
|
24
|
+
# Builds an action pipeline for a directory.
|
|
25
25
|
class ActionsFactory
|
|
26
|
-
LIMIT = 143 # Synology eCryptfs limitation.
|
|
26
|
+
LIMIT = 143 # Matches the Synology eCryptfs limitation.
|
|
27
27
|
|
|
28
28
|
def initialize(cfg)
|
|
29
29
|
@cfg = cfg
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
def produce(dir) # rubocop:disable Metrics/
|
|
32
|
+
def produce(dir) # rubocop:disable Metrics/AbcSize
|
|
33
33
|
if @cfg.lim?
|
|
34
34
|
[
|
|
35
35
|
OmitAction.new(LIMIT),
|
|
@@ -37,7 +37,7 @@ module Renamr
|
|
|
37
37
|
]
|
|
38
38
|
else
|
|
39
39
|
[
|
|
40
|
-
PointAction.new(dir), #
|
|
40
|
+
PointAction.new(dir), # Runs first.
|
|
41
41
|
@cfg.pos.nil? ? nil : RemoveAction.new(@cfg.pos, @cfg.len),
|
|
42
42
|
@cfg.src.nil? ? nil : SubstituteAction.new(@cfg.src, @cfg.dst),
|
|
43
43
|
ManualLocalizationAction.new,
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# vi:
|
|
4
|
-
# SPDX-FileCopyrightText: 2018-
|
|
3
|
+
# vi: et lbr sw=2 ts=2 tw=79 wrap
|
|
4
|
+
# SPDX-FileCopyrightText: 2018-2026 David Rabkin
|
|
5
5
|
# SPDX-License-Identifier: 0BSD
|
|
6
6
|
|
|
7
7
|
require_relative 'action'
|
|
8
8
|
|
|
9
9
|
module Renamr
|
|
10
|
-
#
|
|
10
|
+
# Transliterates accented Latin characters to their ASCII equivalents.
|
|
11
11
|
class ManualLocalizationAction < Action
|
|
12
|
-
SRC = 'ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđ'\
|
|
13
|
-
'ÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏ'\
|
|
14
|
-
'ìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅ'\
|
|
15
|
-
'ņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝ'\
|
|
16
|
-
'ŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝ'\
|
|
12
|
+
SRC = 'ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđ' \
|
|
13
|
+
'ÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏ' \
|
|
14
|
+
'ìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅ' \
|
|
15
|
+
'ņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝ' \
|
|
16
|
+
'ŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝ' \
|
|
17
17
|
'ýÿŶŷŸŹźŻżŽž'
|
|
18
|
-
DST = 'AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDd'\
|
|
19
|
-
'EEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIII'\
|
|
20
|
-
'iiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnN'\
|
|
21
|
-
'nNnnNnOOOOOOooooooOoOoOoRrRrRrSsSs'\
|
|
22
|
-
'SsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwY'\
|
|
18
|
+
DST = 'AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDd' \
|
|
19
|
+
'EEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIII' \
|
|
20
|
+
'iiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnN' \
|
|
21
|
+
'nNnnNnOOOOOOooooooOoOoOoRrRrRrSsSs' \
|
|
22
|
+
'SsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwY' \
|
|
23
23
|
'yyYyYZzZzZz'
|
|
24
24
|
|
|
25
25
|
def do(src)
|
data/lib/renamr/omit.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# vi:
|
|
4
|
-
# SPDX-FileCopyrightText: 2018-
|
|
3
|
+
# vi: et lbr sw=2 ts=2 tw=79 wrap
|
|
4
|
+
# SPDX-FileCopyrightText: 2018-2026 David Rabkin
|
|
5
5
|
# SPDX-License-Identifier: 0BSD
|
|
6
6
|
|
|
7
7
|
require_relative 'action'
|
|
8
8
|
|
|
9
9
|
module Renamr
|
|
10
|
-
#
|
|
10
|
+
# Skips file names shorter than the limit.
|
|
11
11
|
class OmitAction < Action
|
|
12
12
|
def initialize(lim)
|
|
13
13
|
super()
|
data/lib/renamr/point.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# vi:
|
|
4
|
-
# SPDX-FileCopyrightText: 2018-
|
|
3
|
+
# vi: et lbr sw=2 ts=2 tw=79 wrap
|
|
4
|
+
# SPDX-FileCopyrightText: 2018-2026 David Rabkin
|
|
5
5
|
# SPDX-License-Identifier: 0BSD
|
|
6
6
|
|
|
7
7
|
require_relative 'action'
|
|
8
8
|
|
|
9
9
|
module Renamr
|
|
10
|
-
#
|
|
10
|
+
# Replaces dots with hyphens, except for the file extension separator.
|
|
11
11
|
class PointAction < Action
|
|
12
12
|
def initialize(dir)
|
|
13
13
|
super()
|
data/lib/renamr/prepend.rb
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# vi:
|
|
4
|
-
# SPDX-FileCopyrightText: 2018-
|
|
3
|
+
# vi: et lbr sw=2 ts=2 tw=79 wrap
|
|
4
|
+
# SPDX-FileCopyrightText: 2018-2026 David Rabkin
|
|
5
5
|
# SPDX-License-Identifier: 0BSD
|
|
6
6
|
|
|
7
7
|
require_relative 'action'
|
|
8
8
|
|
|
9
9
|
module Renamr
|
|
10
|
-
#
|
|
10
|
+
# Inserts a user-provided string at the given position.
|
|
11
11
|
class PrependAction < Action
|
|
12
12
|
def initialize(beg, pre) # rubocop:disable Lint/MissingSuper
|
|
13
13
|
raise 'beg cannot be nil.' if beg.nil?
|
|
14
|
-
raise '
|
|
14
|
+
raise 'pre cannot be nil.' if pre.nil?
|
|
15
15
|
|
|
16
16
|
@beg = beg
|
|
17
17
|
@pre = pre
|
data/lib/renamr/prepend_date.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# vi:
|
|
4
|
-
# SPDX-FileCopyrightText: 2018-
|
|
3
|
+
# vi: et lbr sw=2 ts=2 tw=79 wrap
|
|
4
|
+
# SPDX-FileCopyrightText: 2018-2026 David Rabkin
|
|
5
5
|
# SPDX-License-Identifier: 0BSD
|
|
6
6
|
|
|
7
7
|
require_relative 'action'
|
|
8
8
|
|
|
9
9
|
module Renamr
|
|
10
|
-
# Prepends file modification
|
|
10
|
+
# Prepends the file modification date.
|
|
11
11
|
class PrependDateAction < Action
|
|
12
12
|
def initialize(dir)
|
|
13
13
|
super()
|
data/lib/renamr/remove.rb
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# vi:
|
|
4
|
-
# SPDX-FileCopyrightText: 2018-
|
|
3
|
+
# vi: et lbr sw=2 ts=2 tw=79 wrap
|
|
4
|
+
# SPDX-FileCopyrightText: 2018-2026 David Rabkin
|
|
5
5
|
# SPDX-License-Identifier: 0BSD
|
|
6
6
|
|
|
7
7
|
require_relative 'action'
|
|
8
8
|
|
|
9
9
|
module Renamr
|
|
10
|
-
# Removes
|
|
10
|
+
# Removes a substring by 1-based position and length.
|
|
11
11
|
class RemoveAction < Action
|
|
12
12
|
def initialize(pos, len)
|
|
13
13
|
super()
|
|
14
|
-
raise 'len cannot
|
|
14
|
+
raise 'len cannot be nil.' if len.nil?
|
|
15
|
+
raise 'len must be positive.' unless len.to_i.positive?
|
|
15
16
|
raise 'pos cannot be nil.' if pos.nil?
|
|
16
|
-
raise 'pos
|
|
17
|
+
raise 'pos must be positive.' unless pos.to_i.positive?
|
|
17
18
|
|
|
18
19
|
@pos = pos.to_i
|
|
19
20
|
@len = len.to_i
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
def do(src)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
src[0..@pos - 1] + src[@pos + @len..]
|
|
24
|
+
src[0...(@pos - 1)] + (src[(@pos - 1 + @len)..] || '')
|
|
26
25
|
end
|
|
27
26
|
end
|
|
28
27
|
end
|
data/lib/renamr/renamer.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# vi:
|
|
4
|
-
# SPDX-FileCopyrightText: 2018-
|
|
3
|
+
# vi: et lbr sw=2 ts=2 tw=79 wrap
|
|
4
|
+
# SPDX-FileCopyrightText: 2018-2026 David Rabkin
|
|
5
5
|
# SPDX-License-Identifier: 0BSD
|
|
6
6
|
|
|
7
7
|
require 'fileutils'
|
|
@@ -10,7 +10,7 @@ require_relative 'factory'
|
|
|
10
10
|
require_relative 'reporter'
|
|
11
11
|
|
|
12
12
|
module Renamr
|
|
13
|
-
# Renames
|
|
13
|
+
# Renames files using configured rules.
|
|
14
14
|
class Renamer
|
|
15
15
|
def initialize
|
|
16
16
|
@cfg = Configurator.new
|
|
@@ -29,20 +29,21 @@ module Renamr
|
|
|
29
29
|
rep.add(File.basename(src), File.basename(dst))
|
|
30
30
|
rescue StandardError => e
|
|
31
31
|
rep.add(File.basename(src), e)
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
msg = ": #{e}"
|
|
33
|
+
msg += " (#{e.class})" if e.class
|
|
34
|
+
msg += "\n\t#{e.backtrace.join("\n\t")}"
|
|
35
|
+
puts msg
|
|
34
36
|
end
|
|
35
37
|
end
|
|
36
38
|
rep.do
|
|
37
39
|
end
|
|
38
40
|
|
|
39
41
|
def unique(dat, nme)
|
|
40
|
-
dst =
|
|
41
|
-
dat.each { |_, d| dst << File.basename(d) } # rubocop:disable Style/HashEachMethods
|
|
42
|
+
dst = dat.map { |_, d| File.basename(d) }
|
|
42
43
|
return nme unless dst.include?(nme)
|
|
43
44
|
|
|
44
45
|
ext = File.extname(nme)
|
|
45
|
-
0.step do |i| #
|
|
46
|
+
0.step do |i| # Iterates indefinitely with an index.
|
|
46
47
|
n = ext.nil? ? "#{nme}-#{i}" : "#{File.basename(nme, ext)}-#{i}#{ext}"
|
|
47
48
|
return n unless dst.include?(n)
|
|
48
49
|
end
|
|
@@ -53,7 +54,8 @@ module Renamr
|
|
|
53
54
|
|
|
54
55
|
dat = []
|
|
55
56
|
act = @fac.produce(dir)
|
|
56
|
-
|
|
57
|
+
|
|
58
|
+
# Skips hidden files.
|
|
57
59
|
Dir.entries(dir).reject { |f| f.start_with?('.') }.sort.each do |nme|
|
|
58
60
|
src = File.join(dir, nme)
|
|
59
61
|
do_dir(src) if @cfg.rec? && File.directory?(src)
|
data/lib/renamr/reporter.rb
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# vi:
|
|
4
|
-
# SPDX-FileCopyrightText: 2018-
|
|
3
|
+
# vi: et lbr sw=2 ts=2 tw=79 wrap
|
|
4
|
+
# SPDX-FileCopyrightText: 2018-2026 David Rabkin
|
|
5
5
|
# SPDX-License-Identifier: 0BSD
|
|
6
6
|
|
|
7
7
|
require 'terminal-table'
|
|
8
8
|
require_relative 'action'
|
|
9
|
+
require_relative 'timer'
|
|
9
10
|
require_relative 'utils'
|
|
10
11
|
|
|
11
12
|
module Renamr
|
|
12
|
-
# Formats and prints
|
|
13
|
+
# Formats and prints rename results.
|
|
13
14
|
# rubocop:disable Style/ClassVars
|
|
14
15
|
class Reporter
|
|
15
16
|
@@tim = Timer.new
|
data/lib/renamr/rutoen.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# vi:
|
|
4
|
-
# SPDX-FileCopyrightText: 2018-
|
|
3
|
+
# vi: et lbr sw=2 ts=2 tw=79 wrap
|
|
4
|
+
# SPDX-FileCopyrightText: 2018-2026 David Rabkin
|
|
5
5
|
# SPDX-License-Identifier: 0BSD
|
|
6
6
|
|
|
7
7
|
require_relative 'action'
|