modname 0.2.3 → 0.2.4
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/bin/modname +2 -2
- data/lib/modname/banner.rb +29 -29
- data/lib/modname/modder.rb +32 -46
- data/lib/modname/version.rb +3 -1
- data/lib/modname.rb +58 -54
- data/readme.md +6 -2
- metadata +12 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ba0fa2d1f63b3777585a4202c0560d15b47c0c345b5c614015baed843d78f099
|
|
4
|
+
data.tar.gz: eb9bbbc814a25107ff88e4dae35ba29a1faebf9701c2af3d70a07a350d2e5eb1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 909a24c120475377a6b323d56b4cf0ab1cb1a8b0d6b41a81eb1b241c8a13cbcf76bbbdaf028101456216d674dc2417e61a478113055838a6438cb646927f4ac1
|
|
7
|
+
data.tar.gz: b6686c14fad14cbd7025d39ef985e8ed6dfcb06f0bed43079ca0a01c53724498a4c124a39a592ea0f4906c2ab581779383bf0099c3184142c0d2fb3f4403294e
|
data/bin/modname
CHANGED
data/lib/modname/banner.rb
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# Modname is a versatile file naming tool for renaming groups of files
|
|
4
|
+
module Modname end
|
|
3
5
|
|
|
4
|
-
Modname::
|
|
5
|
-
#{'Usage:'.cyan} modname [options] <match> [transform]
|
|
6
|
+
Modname::HELP_BANNER = <<~HELP.freeze
|
|
7
|
+
#{'Usage:'.cyan} modname [options] <match> [transform]
|
|
6
8
|
|
|
7
|
-
#{'modname | rename files, fast'.cyan}
|
|
8
|
-
#{'--------┼----------------------------'.cyan}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
#{'modname | rename files, fast'.cyan}
|
|
10
|
+
#{'--------┼----------------------------'.cyan}
|
|
11
|
+
-e #{'|'.cyan} change file extensions
|
|
12
|
+
-f #{'|'.cyan} force run; don't pre-check
|
|
13
|
+
-r #{'|'.cyan} run modname recursively
|
|
14
|
+
-h #{'|'.cyan} show more help, examples
|
|
13
15
|
HELP
|
|
14
16
|
|
|
17
|
+
Modname::V_HELP_BANNER = <<~VHELP.freeze
|
|
18
|
+
#{Modname::HELP_BANNER}
|
|
19
|
+
#{'commands'.cyan}
|
|
20
|
+
file names
|
|
21
|
+
[match] [trans] => modify a pattern in filenames
|
|
22
|
+
[match] => delete a pattern from filenames
|
|
15
23
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
[match] [trans] => modify a pattern in filenames
|
|
21
|
-
[match] => delete a pattern from filenames
|
|
24
|
+
extensions (-e)
|
|
25
|
+
[old] [new] => move file extensions, <old> to <new>
|
|
26
|
+
[ext] => lowercase one extension type (EXT => ext)
|
|
27
|
+
nil => move all extensions to lower case
|
|
22
28
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
#{'examples'.cyan}
|
|
30
|
+
file names
|
|
31
|
+
modname hello => deletes 'hello' from all filenames
|
|
32
|
+
modname hello byebye => replace 'hello' with byebye
|
|
27
33
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
modname hello byebye => replace 'hello' with byebye
|
|
34
|
+
extensions (-e)
|
|
35
|
+
modname -e txt md => move all txt files to markdown
|
|
36
|
+
modname -e mov mp4 => move all mov files to mp4
|
|
32
37
|
|
|
33
|
-
|
|
34
|
-
modname -e txt md => move all txt files to markdown
|
|
35
|
-
modname -e mov mp4 => move all mov files to mp4
|
|
36
|
-
|
|
37
|
-
#{'Note:'.cyan} <required> [optional]
|
|
38
|
+
#{'Note:'.cyan} <required> [optional]
|
|
38
39
|
VHELP
|
|
39
|
-
|
data/lib/modname/modder.rb
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# modder, the modname helper
|
|
2
4
|
# generally: o-old, n-new
|
|
3
5
|
|
|
4
|
-
|
|
5
6
|
# any module including modder should implement:
|
|
6
7
|
# @transfer => hash of file transfers to occur
|
|
7
8
|
# @options => hash with :recurse and :force
|
|
8
9
|
|
|
9
|
-
|
|
10
10
|
# extensions
|
|
11
11
|
module Modder
|
|
12
|
-
|
|
13
12
|
# rename files based on regular expressions
|
|
14
13
|
def regex(args = [])
|
|
15
14
|
match, trans = Modder.parse args
|
|
@@ -17,15 +16,14 @@ module Modder
|
|
|
17
16
|
Modder.files(@options[:recurse]).each do |file|
|
|
18
17
|
new = file.sub Regexp.new(match), trans
|
|
19
18
|
|
|
20
|
-
next if
|
|
19
|
+
next if new == file || new == '' # no changes
|
|
21
20
|
|
|
22
21
|
@transfer[file] = new
|
|
23
22
|
end
|
|
24
23
|
|
|
25
|
-
Modder.finish @transfer, @options[:force]
|
|
24
|
+
Modder.finish @transfer, force: @options[:force]
|
|
26
25
|
end
|
|
27
26
|
|
|
28
|
-
|
|
29
27
|
# change one file extension to another's type
|
|
30
28
|
def exts(args = [])
|
|
31
29
|
match, trans = Modder.parse args
|
|
@@ -45,34 +43,32 @@ module Modder
|
|
|
45
43
|
@transfer[file] = new
|
|
46
44
|
end
|
|
47
45
|
|
|
48
|
-
Modder.finish @transfer, @options[:force]
|
|
46
|
+
Modder.finish @transfer, force: @options[:force]
|
|
49
47
|
end
|
|
50
48
|
end
|
|
51
49
|
|
|
52
50
|
# top level wrapper for exts
|
|
53
|
-
def undercase_ext(ext =
|
|
51
|
+
def undercase_ext(ext = '')
|
|
54
52
|
transfer = Modder.undercase_ext_get ext, @options[:recurse]
|
|
55
53
|
Modder.undercase_ext_set ext, transfer, @options[:force]
|
|
56
54
|
end
|
|
57
55
|
end
|
|
58
56
|
|
|
59
|
-
|
|
60
57
|
# module methods
|
|
61
58
|
class << Modder
|
|
62
|
-
|
|
63
59
|
# return appropriate args, repairing if undefined
|
|
64
60
|
def parse(args)
|
|
65
61
|
match = args.shift
|
|
66
62
|
trans = args.shift
|
|
67
|
-
match =
|
|
68
|
-
trans =
|
|
69
|
-
|
|
63
|
+
match = '' if match.nil?
|
|
64
|
+
trans = '' if trans.nil?
|
|
65
|
+
[match, trans]
|
|
70
66
|
end
|
|
71
67
|
|
|
72
68
|
# double check transformations
|
|
73
69
|
def confirm?
|
|
74
|
-
print
|
|
75
|
-
|
|
70
|
+
print 'Are these changes ok? [yN] '
|
|
71
|
+
$stdin.gets.chomp.downcase[0] == 'y'
|
|
76
72
|
end
|
|
77
73
|
|
|
78
74
|
# return a list of files to examine
|
|
@@ -84,63 +80,54 @@ class << Modder
|
|
|
84
80
|
end
|
|
85
81
|
end
|
|
86
82
|
|
|
87
|
-
|
|
88
83
|
# show the status of current files
|
|
89
84
|
def status(transfer)
|
|
90
85
|
if transfer.empty?
|
|
91
|
-
puts
|
|
86
|
+
puts 'No matches found.'.yellow
|
|
92
87
|
else
|
|
93
|
-
puts
|
|
88
|
+
puts 'Planned file actions:'.green
|
|
94
89
|
transfer.each { |o, n| puts "\t#{o} -> #{n.green}" }
|
|
95
90
|
end
|
|
96
91
|
end
|
|
97
92
|
|
|
98
93
|
# rename all files
|
|
99
|
-
def execute(transfer, force
|
|
94
|
+
def execute(transfer, force: false)
|
|
100
95
|
transfer.each { |o, n| Modder.rename o, n, force }
|
|
101
96
|
end
|
|
102
97
|
|
|
103
|
-
|
|
104
98
|
# finish up execution, highest level wrapper
|
|
105
|
-
def finish(transfer, force
|
|
106
|
-
|
|
99
|
+
def finish(transfer, force: false)
|
|
107
100
|
# print changes, return if none
|
|
108
101
|
Modder.status transfer
|
|
109
102
|
return if transfer.empty?
|
|
110
103
|
|
|
111
104
|
if force || Modder.confirm?
|
|
112
|
-
Modder.execute transfer, force
|
|
113
|
-
puts
|
|
105
|
+
Modder.execute transfer, force: force
|
|
106
|
+
puts 'Modifications complete.'
|
|
114
107
|
else
|
|
115
|
-
puts
|
|
108
|
+
puts 'No modifications done.'
|
|
116
109
|
end
|
|
117
110
|
end
|
|
118
111
|
|
|
119
112
|
# try to rename a given file
|
|
120
|
-
def rename(
|
|
121
|
-
|
|
122
|
-
exist = "#{'Error:'.red} target file |#{n.green}| already exists"
|
|
123
|
-
|
|
124
|
-
# only overwrite when forced
|
|
125
|
-
if (!force) && File.exist?(n)
|
|
126
|
-
raise(exist)
|
|
127
|
-
else
|
|
128
|
-
File.rename(o, n)
|
|
129
|
-
end
|
|
113
|
+
def rename(old, new, force)
|
|
114
|
+
exist = "#{'Error:'.red} target file |#{new.green}| already exists"
|
|
130
115
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
puts e.message
|
|
134
|
-
end
|
|
135
|
-
end
|
|
116
|
+
# only overwrite when forced
|
|
117
|
+
raise(exist) if (!force) && File.exist?(new)
|
|
136
118
|
|
|
119
|
+
File.rename(old, new)
|
|
120
|
+
rescue StandardError => e
|
|
121
|
+
puts "#{'Error:'.red} could not move |#{old.red}| to |#{new.green}|"
|
|
122
|
+
puts e.message
|
|
123
|
+
end
|
|
137
124
|
|
|
138
125
|
# get all extensions to change
|
|
139
126
|
def undercase_ext_get(ext, recurse)
|
|
140
|
-
transfer =
|
|
127
|
+
transfer = {}
|
|
141
128
|
allexts = ext.empty?
|
|
142
129
|
Modder.files(recurse).each do |file|
|
|
143
|
-
ext = file.split(
|
|
130
|
+
ext = file.split('.').last if allexts
|
|
144
131
|
|
|
145
132
|
new = file.sub(/#{ext}$/i, ext.downcase)
|
|
146
133
|
next if new == file || ext == file # no changes or extension
|
|
@@ -156,7 +143,7 @@ class << Modder
|
|
|
156
143
|
# not case sensitive and therefore wont distiniguish between HI and hi.
|
|
157
144
|
# to get around this, we can set HI to HI.hash, then set HI.hash to hi
|
|
158
145
|
def undercase_ext_set(ext, transfer, force)
|
|
159
|
-
puts
|
|
146
|
+
puts 'Lowering extension: '.green + (ext.empty? ? '*' : ext)
|
|
160
147
|
|
|
161
148
|
Modder.status transfer
|
|
162
149
|
return if transfer.empty?
|
|
@@ -175,10 +162,9 @@ class << Modder
|
|
|
175
162
|
|
|
176
163
|
Modder.execute temp
|
|
177
164
|
Modder.execute final
|
|
178
|
-
puts
|
|
165
|
+
puts 'Modifications complete.'
|
|
179
166
|
else
|
|
180
|
-
puts
|
|
167
|
+
puts 'No modifications done.'
|
|
181
168
|
end
|
|
182
169
|
end
|
|
183
170
|
end
|
|
184
|
-
|
data/lib/modname/version.rb
CHANGED
data/lib/modname.rb
CHANGED
|
@@ -1,75 +1,79 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
require "modname/banner"
|
|
6
|
-
require "modname/modder"
|
|
7
|
-
require "modname/version"
|
|
3
|
+
# parse modname's command line args
|
|
8
4
|
|
|
5
|
+
require 'colored'
|
|
6
|
+
require 'modname/banner'
|
|
7
|
+
require 'modname/modder'
|
|
8
|
+
require 'modname/version'
|
|
9
9
|
|
|
10
|
+
# Modname is a versatile file naming tool for renaming groups of files
|
|
10
11
|
module Modname
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
# defining Modname.run
|
|
13
|
+
class << self
|
|
14
|
+
def run(args) = Driver.new.run(args)
|
|
13
15
|
end
|
|
14
16
|
end
|
|
15
17
|
|
|
18
|
+
# Modname module containing the CLI driver
|
|
19
|
+
module Modname
|
|
20
|
+
# Driver class handles command-line argument parsing and execution
|
|
21
|
+
class Driver
|
|
22
|
+
include Modder
|
|
16
23
|
|
|
17
|
-
|
|
18
|
-
include Modder
|
|
19
|
-
|
|
20
|
-
attr_reader :options
|
|
24
|
+
attr_reader :options
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
def initialize
|
|
27
|
+
@options = { force: false, recurse: false }
|
|
28
|
+
@transfer = {}
|
|
29
|
+
end
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
# parse user arguments
|
|
32
|
+
def run(args)
|
|
33
|
+
if args.empty?
|
|
34
|
+
puts Modname::HELP_BANNER
|
|
35
|
+
else
|
|
36
|
+
opts = parse args
|
|
37
|
+
cmd = opts[:cmd]
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
case cmd
|
|
40
|
+
when 'file'
|
|
41
|
+
regex opts[:args]
|
|
38
42
|
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
when 'ext'
|
|
44
|
+
exts opts[:args]
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
when 'help'
|
|
47
|
+
puts Modname::V_HELP_BANNER
|
|
44
48
|
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
when 'version'
|
|
50
|
+
puts Modname::VERSION
|
|
51
|
+
end
|
|
47
52
|
end
|
|
48
53
|
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# parse out arguments
|
|
52
|
-
def parse(args)
|
|
53
|
-
opts = {:cmd => "file", :args => []}
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
# parse out arguments
|
|
56
|
+
def parse(args)
|
|
57
|
+
opts = { cmd: 'file', args: [] }
|
|
58
|
+
|
|
59
|
+
args.each do |opt|
|
|
60
|
+
case opt
|
|
61
|
+
when '-f'
|
|
62
|
+
@options[:force] = true
|
|
63
|
+
when '-r'
|
|
64
|
+
@options[:recurse] = true
|
|
65
|
+
when '-e', '--ext'
|
|
66
|
+
opts[:cmd] = 'ext'
|
|
67
|
+
when '-h', '--help'
|
|
68
|
+
opts[:cmd] = 'help'
|
|
69
|
+
when '-v', '--version'
|
|
70
|
+
opts[:cmd] = 'version'
|
|
71
|
+
else # command argument
|
|
72
|
+
opts[:args] << opt
|
|
73
|
+
end
|
|
69
74
|
end
|
|
70
|
-
end
|
|
71
75
|
|
|
72
|
-
|
|
76
|
+
opts
|
|
77
|
+
end
|
|
73
78
|
end
|
|
74
79
|
end
|
|
75
|
-
|
data/readme.md
CHANGED
|
@@ -3,8 +3,6 @@ modname
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
[](https://badge.fury.io/rb/modname)
|
|
6
|
-
[](https://travis-ci.org/jeremywrnr/modname)
|
|
7
|
-
[](https://codeclimate.com/github/jeremywrnr/modname)
|
|
8
6
|
[](http://jeremywrnr.com/mit-license)
|
|
9
7
|
|
|
10
8
|
|
|
@@ -54,6 +52,12 @@ examples
|
|
|
54
52
|
Note: <required> [optional]
|
|
55
53
|
```
|
|
56
54
|
|
|
55
|
+
### examples
|
|
56
|
+
|
|
57
|
+
modname -e jpeg jpg # change all jpeg file exts to jpg
|
|
58
|
+
modname -e # change all file extensions to lowercase
|
|
59
|
+
modname '(.*)' 'jeremy \1' # use grouping to prepend string
|
|
60
|
+
|
|
57
61
|
|
|
58
62
|
## development / testing
|
|
59
63
|
|
metadata
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: modname
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jeremy Warner
|
|
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
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: colored
|
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
|
16
15
|
requirements:
|
|
17
|
-
- - "
|
|
16
|
+
- - "~>"
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
18
|
version: '1.2'
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
|
-
- - "
|
|
23
|
+
- - "~>"
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
version: '1.2'
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
@@ -39,7 +38,7 @@ dependencies:
|
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
39
|
version: '0'
|
|
41
40
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
41
|
+
name: rspec
|
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
|
44
43
|
requirements:
|
|
45
44
|
- - ">="
|
|
@@ -53,7 +52,7 @@ dependencies:
|
|
|
53
52
|
- !ruby/object:Gem::Version
|
|
54
53
|
version: '0'
|
|
55
54
|
- !ruby/object:Gem::Dependency
|
|
56
|
-
name: rspec
|
|
55
|
+
name: rspec-mocks
|
|
57
56
|
requirement: !ruby/object:Gem::Requirement
|
|
58
57
|
requirements:
|
|
59
58
|
- - ">="
|
|
@@ -67,19 +66,19 @@ dependencies:
|
|
|
67
66
|
- !ruby/object:Gem::Version
|
|
68
67
|
version: '0'
|
|
69
68
|
- !ruby/object:Gem::Dependency
|
|
70
|
-
name:
|
|
69
|
+
name: simplecov
|
|
71
70
|
requirement: !ruby/object:Gem::Requirement
|
|
72
71
|
requirements:
|
|
73
|
-
- - "
|
|
72
|
+
- - "~>"
|
|
74
73
|
- !ruby/object:Gem::Version
|
|
75
|
-
version:
|
|
74
|
+
version: 0.22.0
|
|
76
75
|
type: :development
|
|
77
76
|
prerelease: false
|
|
78
77
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
78
|
requirements:
|
|
80
|
-
- - "
|
|
79
|
+
- - "~>"
|
|
81
80
|
- !ruby/object:Gem::Version
|
|
82
|
-
version:
|
|
81
|
+
version: 0.22.0
|
|
83
82
|
description: easily rename groups of files with regex replacements.
|
|
84
83
|
email: jeremywrnr@gmail.com
|
|
85
84
|
executables:
|
|
@@ -97,7 +96,6 @@ homepage: http://github.com/jeremywrnr/modname
|
|
|
97
96
|
licenses:
|
|
98
97
|
- MIT
|
|
99
98
|
metadata: {}
|
|
100
|
-
post_install_message:
|
|
101
99
|
rdoc_options: []
|
|
102
100
|
require_paths:
|
|
103
101
|
- lib
|
|
@@ -112,10 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
112
110
|
- !ruby/object:Gem::Version
|
|
113
111
|
version: '0'
|
|
114
112
|
requirements: []
|
|
115
|
-
|
|
116
|
-
rubygems_version: 2.5.1
|
|
117
|
-
signing_key:
|
|
113
|
+
rubygems_version: 3.7.2
|
|
118
114
|
specification_version: 4
|
|
119
115
|
summary: a versatile file naming tool.
|
|
120
116
|
test_files: []
|
|
121
|
-
has_rdoc:
|