rename2mac 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -5
- data/bin/rename2mac +62 -18
- data/rename2mac-0.9.4.gem +0 -0
- data/rename2mac.gemspec +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b38ef30c1d7c15e3ba46586d9e447351956d4f8a
|
4
|
+
data.tar.gz: fd5d7c3c8b53f7c4e67561b6de5f4aa545ab58d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8556b354e5595741d2cbc2ea29d4f7f210b7693ca1e718e8cbda4fb7b64cd6c79921e8cfe14c7db25509be5dd385057b491e8324b9c68a1aed67d99142e36a4
|
7
|
+
data.tar.gz: a8f94c4d709718224068ead0dc367d36825444bd1ecc54de80ba7309242b5151adf3ed88dbe3b8547bc85fcecf279d6aa2c32a9cb5d8c8be584733b238cc1780
|
data/README.md
CHANGED
@@ -4,7 +4,11 @@ Rename folderful of filenames to Mac OS X supported format (UTF8-MAC). Mac OS X
|
|
4
4
|
|
5
5
|
Background:
|
6
6
|
--------------------------
|
7
|
-
|
7
|
+
When I use Mac OS X Finder, I have a lot of issue when dealing with Asian filenames, such as Japanese/Korean/Chinese characters. Previous attempt using convmv and iconv tools failed to fix the problem led me created this tool. I am sure this can fix other international characters too.
|
8
|
+
|
9
|
+
The Mac OS X system handles filenames in modified Unicode format called UTF8-Mac. If a filename contain none UTF8-Mac character, the Finder may exihibit behavour such as disappearing file, constant refresh, unable to open file, etc. To fix this problem, the file has to be renamed using UTF8-Mac format.
|
10
|
+
|
11
|
+
For more information read https://www.j3e.de/linux/convmv/man/#hfs__on_os_x___darwin
|
8
12
|
|
9
13
|
Installation:
|
10
14
|
--------------------------
|
@@ -14,13 +18,17 @@ Installation:
|
|
14
18
|
|
15
19
|
Usage:
|
16
20
|
--------------------------
|
17
|
-
rename2mac \[
|
21
|
+
rename2mac \[arguments\] \<directory\>
|
18
22
|
|
19
|
-
|
23
|
+
Arguments:
|
20
24
|
--------------------------
|
21
|
-
|
25
|
+
--noop -n Make no changes
|
26
|
+
--recursive -r Recursively rename
|
27
|
+
--force -f Force overwrite existing file if it exists
|
28
|
+
--quiet -q Do not output individual results to screen
|
29
|
+
--help -h Display current help message
|
22
30
|
|
23
31
|
License:
|
24
32
|
--------------------------
|
25
33
|
MIT
|
26
|
-
Mac Ma
|
34
|
+
Mac Ma comomac (at) runbox (dot) com (C) 2013 Copyright
|
data/bin/rename2mac
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
#
|
5
5
|
# Rename folderful of filenames to Mac OS X supported format (UTF8-MAC). Mac OS X use only.
|
6
|
-
# Mac Ma
|
6
|
+
# Mac Ma comomac (at) runbox (dot) com (c) Copyright 2013
|
7
7
|
# License MIT
|
8
8
|
#
|
9
9
|
|
@@ -17,13 +17,18 @@ unless RbConfig::CONFIG['host_os'] =~ /darwin/
|
|
17
17
|
exit
|
18
18
|
end
|
19
19
|
|
20
|
-
require '
|
20
|
+
require 'getoptlong'
|
21
21
|
require 'fileutils'
|
22
22
|
require 'term/ansicolor'
|
23
23
|
|
24
24
|
include Term::ANSIColor
|
25
25
|
|
26
26
|
class String
|
27
|
+
# escape [] and {} character for Dir.glob to use
|
28
|
+
def glob_escape
|
29
|
+
self.gsub(/([\[\]\{\}\*\?\\])/, '\\\\\1')
|
30
|
+
end
|
31
|
+
|
27
32
|
def to_m
|
28
33
|
# convert string to UTF8-MAC format
|
29
34
|
self.encode('UTF8-MAC', 'UTF-8')
|
@@ -85,28 +90,67 @@ def Dir.restricted?( dir, excludes=[] )
|
|
85
90
|
return false
|
86
91
|
end
|
87
92
|
|
93
|
+
def show_help
|
94
|
+
puts \
|
95
|
+
%Q{Usage:
|
96
|
+
rename2mac [arguments] <dir>
|
97
|
+
|
98
|
+
Arguments:
|
99
|
+
--noop -n Make no changes
|
100
|
+
--recursive -r Recursively rename
|
101
|
+
--force -f Force overwrite existing file if it exists
|
102
|
+
--quiet -q Do not output individual results to screen
|
103
|
+
--help -h Display current help message}
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
opts = GetoptLong.new(
|
109
|
+
[ '--noop', '-n', GetoptLong::NO_ARGUMENT ],
|
110
|
+
[ '--recursive', '-r', GetoptLong::NO_ARGUMENT ],
|
111
|
+
[ '--force', '-f', GetoptLong::NO_ARGUMENT ],
|
112
|
+
[ '--quiet', '-q', GetoptLong::NO_ARGUMENT ],
|
113
|
+
[ '--help', '-h', GetoptLong::NO_ARGUMENT ]
|
114
|
+
)
|
115
|
+
|
116
|
+
noop = recursive = force = quiet = false
|
117
|
+
|
118
|
+
opts.each do |opt, arg|
|
119
|
+
noop = true if opt == '--noop'
|
120
|
+
recursive = true if opt == '--recursive'
|
121
|
+
force = true if opt == '--force'
|
122
|
+
quiet = true if opt == '--quiet'
|
123
|
+
|
124
|
+
if opt == '--help'
|
125
|
+
show_help
|
126
|
+
exit
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
|
88
131
|
if ARGV.length == 0
|
89
|
-
|
132
|
+
show_help
|
90
133
|
exit
|
91
134
|
else
|
92
|
-
|
93
|
-
# -n argument will show what files/folders will be changed, without making changes
|
94
|
-
noop = true
|
95
|
-
src_dir = File.expand_path(ARGV[1])
|
96
|
-
else
|
97
|
-
noop = false
|
98
|
-
src_dir = File.expand_path(ARGV[0])
|
99
|
-
end
|
135
|
+
src_dir = File.expand_path(ARGV[0])
|
100
136
|
|
101
137
|
unless FileTest.directory?( src_dir )
|
102
|
-
puts "
|
138
|
+
puts "Dir don't exists. #{src_dir}"
|
103
139
|
exit
|
104
140
|
end
|
105
141
|
end
|
106
142
|
|
143
|
+
|
107
144
|
total_success = 0 # success rename counter
|
108
145
|
total_fail = 0 # fail rename counter
|
109
146
|
|
147
|
+
# set wildcard if recursive or not
|
148
|
+
if recursive
|
149
|
+
wildcard = '/**/*'
|
150
|
+
else
|
151
|
+
wildcard = '/*'
|
152
|
+
end
|
153
|
+
|
110
154
|
# repeat if discover some success, because new files might be discovered
|
111
155
|
total_files = 0
|
112
156
|
flag = true
|
@@ -114,9 +158,9 @@ while flag
|
|
114
158
|
total_files = 0
|
115
159
|
flag = false
|
116
160
|
|
117
|
-
|
118
|
-
|
119
|
-
|
161
|
+
Dir.glob(File.expand_path(src_dir).glob_escape + wildcard).delete_if { |fullpath|
|
162
|
+
Dir.restricted?( fullpath )
|
163
|
+
}.each { |fullpath|
|
120
164
|
next if fullpath.bn[0..0] == '.'
|
121
165
|
|
122
166
|
total_files += 1
|
@@ -136,10 +180,10 @@ while flag
|
|
136
180
|
# rename directory or file
|
137
181
|
begin
|
138
182
|
# tell program to restart the rename from beginning after finish, because some files maybe revealed after rename
|
139
|
-
FileUtils.mv(fullpath, fullpath.dn.to_m + '/' + fullpath.bn.to_m, :noop => noop)
|
140
|
-
fullpath.print_diff
|
183
|
+
FileUtils.mv(fullpath, fullpath.dn.to_m + '/' + fullpath.bn.to_m, :noop => noop, :force => force)
|
184
|
+
fullpath.print_diff unless quiet
|
141
185
|
total_success += 1
|
142
|
-
flag = true
|
186
|
+
flag = true unless noop
|
143
187
|
rescue => e
|
144
188
|
print 'failed: '
|
145
189
|
fullpath.print_diff
|
Binary file
|
data/rename2mac.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rename2mac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mac Ma
|
@@ -34,6 +34,7 @@ extra_rdoc_files: []
|
|
34
34
|
files:
|
35
35
|
- LICENSE
|
36
36
|
- README.md
|
37
|
+
- rename2mac-0.9.4.gem
|
37
38
|
- rename2mac.gemspec
|
38
39
|
- bin/rename2mac
|
39
40
|
homepage: http://rubygems.org/gems/rename2mac
|