rename2mac 0.9.6 → 0.9.8.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b0752b15c305afb14b83b8794fead5fa50a94c2
4
- data.tar.gz: b4e0469f9824096e2a13191eb93f24ba22345678
3
+ metadata.gz: 639308c32cb112d30ac7b62d9208da208c04d62c
4
+ data.tar.gz: 0e64ac5cf4deff332f95ee2b6a2b72f39bb3bd05
5
5
  SHA512:
6
- metadata.gz: aa80f1b76e444d6abcdec66b09ad2f082c09844ef9e6ef357b769a78dc9de513299ec55b42515a772be1628578bffe761fef9d425904a3b265b948f1a2575764
7
- data.tar.gz: 1299fc239123474762729e7d5e330f5c69ed0a6107f921b5ec8b1b626f1a46cf22346adcd80a593f587403533bf76a25cc1ca566c0522d6fa9618945f3d8e834
6
+ metadata.gz: 021f07d31b1029af76984e348973629d96b0701179d9b9124cc58ec8e6da99dbc5d0f88bf75159c429f9b338fe571966f234ce0b57e4724565a1391983453f96
7
+ data.tar.gz: 7bb51910102e72e041588dd366a0396fd9252500ff9f714c286f250433cec96fdd36e9ef71ac5869231720754c30f0bce44b60bfd0078a090a9de4693af3e121
data/README.md CHANGED
@@ -19,7 +19,7 @@ rename2mac \[arguments\] \<directory\>
19
19
 
20
20
  #### Arguments: ####
21
21
  --noop -n Make no changes
22
- --recursive -r Recursively rename
22
+ --local -l Scan local directory only, do not scan recursively.
23
23
  --force -f Force overwrite existing file if it exists
24
24
  --quiet -q Do not output individual results to screen
25
25
  --help -h Display current help message
data/bin/rename2mac CHANGED
@@ -1,5 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
- #encoding: utf-8
2
+ # encoding: utf-8
3
+
4
+ # making sure program runs in UTF-8 encoding in any environment
5
+ # Encoding.default_external = Encoding::UTF_8
6
+ # Encoding.default_internal = Encoding::UTF_8
7
+
3
8
 
4
9
  #
5
10
  # Rename folderful of filenames to Mac OS X supported format (UTF8-MAC). Mac OS X use only.
@@ -7,6 +12,8 @@
7
12
  # License MIT
8
13
  #
9
14
 
15
+ $LOAD_PATH << File.expand_path( File.dirname( File.expand_path( __FILE__ ) ) + '/../lib' )
16
+
10
17
  if RUBY_VERSION <= '1.9'
11
18
  puts 'Require Ruby 1.9 or above.'
12
19
  exit
@@ -19,85 +26,20 @@ end
19
26
 
20
27
  require 'getoptlong'
21
28
  require 'fileutils'
29
+ require 'rename2mac/libs'
22
30
  require 'term/ansicolor'
23
31
 
24
32
  include Term::ANSIColor
25
33
 
26
- class String
27
- # escape [] and {} character for Dir.glob to use
28
- def glob_escape
29
- self.gsub(/([\[\]\{\}\*\?\\])/, '\\\\\1')
30
- end
31
-
32
- def to_m
33
- # convert string to UTF8-MAC format
34
- self.encode('UTF8-MAC', 'UTF-8')
35
-
36
- # convert with extra function of replace invalid character to null
37
- #self.encode('UTF8-MAC', 'UTF-8', invalid: :replace, undef: :replace, replace: '')
38
- end
39
-
40
- def to_u
41
- # convert string to UTF-8 format
42
- self.encode('UTF-8', 'UTF8-MAC')
43
-
44
- # convert with extra function of replace invalid character to null
45
- #self.encode('UTF-8', 'UTF8-MAC', invalid: :replace, undef: :replace, replace: '')
46
- end
47
-
48
- def dn
49
- File.dirname( self )
50
- end
51
-
52
- def bn
53
- File.basename( self )
54
- end
55
-
56
- def um_different?
57
- # return if the string is different when converted to UTF8-MAC format
58
- self.unpack('H*') != self.to_m.unpack('H*')
59
- end
60
-
61
- def print_diff
62
- # highlight the character that is not UTF8-MAC compatible
63
- print self.dn + '/'
64
- self.bn.each_char { |c|
65
- if c.um_different?
66
- print c.red.bold
67
- else
68
- print c
69
- end
70
- }
71
- puts
72
- end
73
- end
74
-
75
- def Dir.restricted?( dir, excludes=[] )
76
- rdirs = [
77
- '.Trash', '.Trashes', '.fseventsd', '.Spotlight-V100', '.DocumentRevisions-V100',
78
- '.$EXTEND',
79
- '_SYNCAPP',
80
- 'Corrupted',
81
- 'System Volume Information', 'RECYCLER',
82
- '.sparsebundle',
83
- '.tmpdir', '.tmp7z',
84
- '.AppleDouble'
85
- ]
86
-
87
- for word in rdirs - excludes
88
- return true if dir.include?( word )
89
- end
90
- return false
91
- end
92
34
 
93
35
  def show_help
94
36
  puts \
95
37
  %Q{Usage:
96
- rename2mac [arguments] <dir>
38
+ rename2mac.rb [arguments] <dir>
97
39
 
98
40
  Arguments:
99
41
  --noop -n Make no changes
100
- --recursive -r Recursively rename
42
+ --local -l Scan local directory only, do not scan recursively.
101
43
  --force -f Force overwrite existing file if it exists
102
44
  --quiet -q Do not output individual results to screen
103
45
  --help -h Display current help message}
@@ -107,19 +49,20 @@ end
107
49
 
108
50
  opts = GetoptLong.new(
109
51
  [ '--noop', '-n', GetoptLong::NO_ARGUMENT ],
110
- [ '--recursive', '-r', GetoptLong::NO_ARGUMENT ],
52
+ [ '--local', '-l', GetoptLong::NO_ARGUMENT ],
111
53
  [ '--force', '-f', GetoptLong::NO_ARGUMENT ],
112
54
  [ '--quiet', '-q', GetoptLong::NO_ARGUMENT ],
113
55
  [ '--help', '-h', GetoptLong::NO_ARGUMENT ]
114
56
  )
115
57
 
116
- noop = recursive = force = quiet = false
58
+ recursive = true
59
+ noop = force = quiet = false
117
60
 
118
61
  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'
62
+ noop = true if opt == '--noop'
63
+ recursive = false if opt == '--local'
64
+ force = true if opt == '--force'
65
+ quiet = true if opt == '--quiet'
123
66
 
124
67
  if opt == '--help'
125
68
  show_help
@@ -158,10 +101,15 @@ while flag
158
101
  total_files = 0
159
102
  flag = false
160
103
 
161
- Dir.glob(File.expand_path(src_dir).glob_escape + wildcard).delete_if { |fullpath|
104
+ Dir.glob(File.expand_path(src_dir).escape_glob + wildcard).delete_if { |fullpath|
162
105
  Dir.restricted?( fullpath )
163
106
  }.each { |fullpath|
164
107
  next if fullpath.bn[0..0] == '.'
108
+ if File.extname( fullpath ) == '.rnm'
109
+ # resume the rename and remove the temporary extension
110
+ FileUtils.mv(fullpath, fullpath.gsub(/\.rnm$/,''), :noop => noop, :force => force)
111
+ next
112
+ end
165
113
 
166
114
  total_files += 1
167
115
 
@@ -180,7 +128,15 @@ while flag
180
128
  # rename directory or file
181
129
  begin
182
130
  # tell program to restart the rename from beginning after finish, because some files maybe revealed after rename
183
- FileUtils.mv(fullpath, fullpath.dn.to_m + '/' + fullpath.bn.to_m, :noop => noop, :force => force)
131
+
132
+ new_fullpath = fullpath.dn.to_m + '/' + fullpath.bn.to_m
133
+ FileUtils.mv(fullpath, new_fullpath, :noop => noop, :force => force)
134
+
135
+ # making two step renaming, to go around yosemite bug where path of utf8 == utf8-mac when renaming file
136
+ # p fullpath == new_fullpath
137
+ # FileUtils.mv(fullpath, new_fullpath + '.rnm', :noop => noop, :force => force)
138
+ # FileUtils.mv(new_fullpath + '.rnm', new_fullpath, :noop => noop, :force => force)
139
+
184
140
  fullpath.print_diff unless quiet
185
141
  total_success += 1
186
142
  flag = true unless noop
@@ -0,0 +1,66 @@
1
+ class String
2
+ # escape [] and {} character for Dir.glob to use
3
+ def escape_glob
4
+ self.gsub(/([\[\]\{\}\*\?\\])/, '\\\\\1')
5
+ end
6
+
7
+ def to_m
8
+ # convert string to UTF8-MAC format
9
+ self.encode('UTF8-MAC', 'UTF-8').force_encoding('UTF-8')
10
+
11
+ # convert with extra function of replace invalid character to null
12
+ #self.encode('UTF8-MAC', 'UTF-8', invalid: :replace, undef: :replace, replace: '')
13
+ end
14
+
15
+ def to_u
16
+ # convert string to UTF-8 format
17
+ self.encode('UTF-8', 'UTF8-MAC')
18
+
19
+ # convert with extra function of replace invalid character to null
20
+ #self.encode('UTF-8', 'UTF8-MAC', invalid: :replace, undef: :replace, replace: '')
21
+ end
22
+
23
+ def dn
24
+ File.dirname( self )
25
+ end
26
+
27
+ def bn
28
+ File.basename( self )
29
+ end
30
+
31
+ def um_different?
32
+ # return if the string is different when converted to UTF8-MAC format
33
+ self.unpack('H*') != self.to_m.unpack('H*')
34
+ end
35
+
36
+ def print_diff
37
+ # highlight the character that is not UTF8-MAC compatible
38
+ print self.dn + '/'
39
+ self.bn.each_char { |c|
40
+ if c.um_different?
41
+ print c.red.bold
42
+ else
43
+ print c
44
+ end
45
+ }
46
+ puts
47
+ end
48
+ end
49
+
50
+ def Dir.restricted?( dir, excludes=[] )
51
+ rdirs = [
52
+ '.Trash', '.Trashes', '.fseventsd', '.Spotlight-V100', '.DocumentRevisions-V100',
53
+ '.$EXTEND',
54
+ '_SYNCAPP',
55
+ 'Corrupted',
56
+ 'System Volume Information', 'RECYCLER',
57
+ '.sparsebundle',
58
+ '.tmpdir', '.tmp7z',
59
+ '.AppleDouble'
60
+ ]
61
+
62
+ for word in rdirs - excludes
63
+ return true if dir.include?( word )
64
+ end
65
+ return false
66
+ end
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+
3
+ module Rename2mac
4
+ VERSION = '0.9.8.1'
5
+ end
6
+
data/rename2mac.gemspec CHANGED
@@ -1,23 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../lib/rename2mac/version', __FILE__)
4
+
5
+
1
6
  Gem::Specification.new do |s|
2
7
  s.name = 'rename2mac'
3
- s.version = '0.9.6'
4
- s.date = '2013-11-15'
5
- s.summary = "rename2mac"
6
- s.description = "Rename folderful of filenames to Mac OS X supported format (UTF8-MAC). Mac OS X use only."
8
+ s.version = Rename2mac::VERSION
9
+ s.summary = "Rename folderful of filenames to Mac OS X supported format (UTF8-MAC). Mac OS X use only."
10
+ s.description = s.summary
7
11
  s.authors = ["Mac Ma"]
8
12
  s.email = 'comomac@runbox.com'
9
13
  s.homepage = 'http://rubygems.org/gems/rename2mac'
10
14
  s.license = 'MIT'
11
15
 
12
- s.required_rubygems_version = '>= 2.0.3'
16
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
13
17
 
14
18
  s.add_dependency 'term-ansicolor', '>= 1.2.2'
15
19
 
16
20
  s.executable = 'rename2mac'
17
21
 
18
- s.files = Dir.glob('*')
19
- s.files.reject! { |fn| fn.include?( '._' ) }
20
- s.files.reject! { |fn| fn.include?( '.DS_Store' ) }
21
- s.files.reject! { |fn| fn.include?( '.git' ) }
22
- s.files.reject! { |fn| fn.include?( '.sublime-' ) }
22
+ s.require_paths = ["lib"]
23
+ s.files = `git ls-files`.split($\)
24
+ s.executables = s.files.grep(%r{^bin/}).map { |f| File.basename(f) }
23
25
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rename2mac
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.9.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mac Ma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-15 00:00:00.000000000 Z
11
+ date: 2015-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: term-ansicolor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.2.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.2.2
27
27
  description: Rename folderful of filenames to Mac OS X supported format (UTF8-MAC).
@@ -34,9 +34,10 @@ extra_rdoc_files: []
34
34
  files:
35
35
  - LICENSE
36
36
  - README.md
37
- - rename2mac-0.9.5.gem
38
- - rename2mac.gemspec
39
37
  - bin/rename2mac
38
+ - lib/rename2mac/libs.rb
39
+ - lib/rename2mac/version.rb
40
+ - rename2mac.gemspec
40
41
  homepage: http://rubygems.org/gems/rename2mac
41
42
  licenses:
42
43
  - MIT
@@ -47,18 +48,19 @@ require_paths:
47
48
  - lib
48
49
  required_ruby_version: !ruby/object:Gem::Requirement
49
50
  requirements:
50
- - - '>='
51
+ - - ">="
51
52
  - !ruby/object:Gem::Version
52
53
  version: '0'
53
54
  required_rubygems_version: !ruby/object:Gem::Requirement
54
55
  requirements:
55
- - - '>='
56
+ - - ">="
56
57
  - !ruby/object:Gem::Version
57
- version: 2.0.3
58
+ version: '0'
58
59
  requirements: []
59
60
  rubyforge_project:
60
- rubygems_version: 2.1.11
61
+ rubygems_version: 2.4.6
61
62
  signing_key:
62
63
  specification_version: 4
63
- summary: rename2mac
64
+ summary: Rename folderful of filenames to Mac OS X supported format (UTF8-MAC). Mac
65
+ OS X use only.
64
66
  test_files: []
data/rename2mac-0.9.5.gem DELETED
Binary file