fixnames 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,22 +4,65 @@ Fix filenames to be bash-script safe and easy to type.
4
4
 
5
5
  ## Usage
6
6
 
7
- See the {Fixnames::Option} for the various settings.
7
+ ee the {Fixnames::Option} for the various settings.
8
8
 
9
+ ``` sh
9
10
  fixnames [options] <files>
10
11
  fixdirs [options] <directories>
12
+ ```
11
13
 
12
14
  ### examples
13
15
 
14
16
  cleanup a dir:
17
+
18
+ ``` sh
15
19
  fixnames -fvv somedir/*
20
+ ```
16
21
 
17
22
  Remove all "`xyzzy`" from filenames:
23
+
24
+ ``` sh
18
25
  fixnames -x xyzzy *
26
+ ```
19
27
 
20
28
  Remove all *digits* from filenames and replace them with "`X`":
29
+
30
+ ``` sh
21
31
  fixnames -x \[0-9] -r X *
32
+ ```
33
+
34
+ ## Suggested Alias
35
+
36
+ I keep the actually changing of massive amounts of filenames
37
+ as something you must _requrest_ proactively. Higher levels of
38
+ verbosity are often essential, and the "-p" flag to _pretend_
39
+ to make changes at first cna save you from MASSIVE data loss.
40
+
41
+ I also include the `-f/--full` option to turn on all of the
42
+ standard filters, which is the aggressive renaming I want to do,
43
+ but i's still probably a good idea tol leave it explicitly "opt-in".
44
+
45
+ Because of all of this, I usually run with this alias:
46
+
47
+ ``` sh
48
+ alias fn='fixnames -fvv'
49
+ ```
50
+
51
+ With that I can use the fact that it auto-supplies `"./*"`
52
+ as what to work on means I can an entire directoy of bad
53
+ files with just `"fn"`.
54
+
55
+ ## Fixdirs still unfinished
56
+
57
+ Recursive-descent into sub-dirs with `fixdirs` isn't really
58
+ finished yet. It might be a bit too much to have a command
59
+ that can wipe out an entire filesystem.
22
60
 
61
+ It should go
62
+ withoutsaying, you should **NEVER** use this stuff as *Root*!
63
+ It doesn't matter, though, as it's proving in practice
64
+ to be suficient easy to just do things directory-at-a-time.
65
+ with `fixnames` by itself.
23
66
 
24
67
  ## Copyright
25
68
 
data/Rakefile CHANGED
@@ -37,12 +37,12 @@ end
37
37
 
38
38
  task :default => :spec
39
39
 
40
- # require 'yard'
41
- # YARD::Rake::YardocTask.new do |t|
42
- # t.files = ['lib/**/*.rb']
43
- # t.files += ['bin/*']
44
- # #t.files += ['spec/**/*_spec.rb']
45
- # #t.options += ['--plugin', 'yard-rspec']
46
- # t.options += ['--markup', 'markdown']
47
- # t.options += ['--debug']
48
- # end
40
+ require 'yard'
41
+ YARD::Rake::YardocTask.new do |t|
42
+ t.files = ['lib/**/*.rb']
43
+ t.files += ['bin/*']
44
+ #t.files += ['spec/**/*_spec.rb']
45
+ #t.options += ['--plugin', 'yard-rspec']
46
+ t.options += ['--markup', 'markdown']
47
+ t.options += ['--debug']
48
+ end
data/bin/fixdirs CHANGED
@@ -20,12 +20,17 @@ end
20
20
  optparse = OptionParser.new do |opts|
21
21
  opts.banner = $banner
22
22
  opts.define_head "Usage: #{$0} [options] <file> [<file> ... ]"
23
+ opts.summary_width = 24
24
+ opts.summary_indent = ' '
25
+
26
+ desc_pad = ' ' * (opts.summary_width + 3)
23
27
 
24
28
  opts.separator ''
25
- opts.separator ' DIRECTORIES:'
29
+ opts.separator 'DIRECTORIES:'
26
30
 
27
31
  opts.on('-g', '--glob=GLOB_STRING',
28
- 'Filename glob inside each directory (default: #{options[:glob]})'
32
+ "Filename glob to use inside each directory for when
33
+ #{desc_pad}we are left to ourself. Default: #{options.dir_glob}"
29
34
  ) { |val| options.dir_glob = val }
30
35
 
31
36
  opts.on('-R', '--[no-]recursive',
@@ -33,7 +38,7 @@ optparse = OptionParser.new do |opts|
33
38
  ) { |val| options.recursive = val }
34
39
 
35
40
  opts.separator ''
36
- opts.separator ' FILTERS:'
41
+ opts.separator 'FILTERS:'
37
42
 
38
43
  opts.on('-A', '--[no-]hack_and',
39
44
  'Replace "&" with "_and_"'
@@ -52,11 +57,14 @@ optparse = OptionParser.new do |opts|
52
57
  ) { |val| options.brackets = val }
53
58
 
54
59
  opts.on('-k', '--[no-]checksums',
55
- 'Trims [0A1B2C3D] CRC32 checksums from names. ( [] or () )'
60
+ "Trims [0A1B2C3D] CRC32 bracket-wrapped checksums
61
+ #{desc_pad}from names, when wrapped with square brackes []
62
+ #{desc_pad}or round parens ()"
56
63
  ) { |val| options.checksums = val }
57
64
 
58
65
  opts.on('-d', '--[no-]dots',
59
- 'Trims excessive dots from files (before the .extention)'
66
+ 'Trims excessive dots from files
67
+ (before the .extention)'
60
68
  ) { |val| options.fix_dots = val }
61
69
 
62
70
  opts.on('-D', '--[no-]dashes',
@@ -72,10 +80,11 @@ optparse = OptionParser.new do |opts|
72
80
  ) { |val| options.lowercase = val }
73
81
 
74
82
  opts.separator ''
75
- opts.separator ' CHARACTERS:'
83
+ opts.separator 'CHARACTERS:'
76
84
 
77
- opts.on('-w', '--whitespace=CHARLIST',
78
- "Characters to treat as whitespace, to be replaced with underscores."
85
+ opts.on('-w', '--whitespace=CHARS',
86
+ "Characters to treat as whitespace, to be
87
+ #{desc_pad}replaced with underscores."
79
88
  ) { |val| options.whitespace = val }
80
89
 
81
90
  opts.on('-W', '--no-whitespace',
@@ -83,7 +92,8 @@ optparse = OptionParser.new do |opts|
83
92
  ) { options.whitespace = nil }
84
93
 
85
94
  opts.on('-s', '--strip=CHARLIST',
86
- "Characters to strip from names. default: #{options.charstrip}"
95
+ "Individual characters to strip from names.
96
+ #{desc_pad}Default: #{options.charstrip}"
87
97
  ) { |val| options.charstrip = val }
88
98
 
89
99
  opts.on('-S', '--no-strip',
@@ -91,29 +101,44 @@ optparse = OptionParser.new do |opts|
91
101
  ) { options.charstrip = nil }
92
102
 
93
103
  opts.separator ''
94
- opts.separator ' REGEX-REPLACE:'
95
-
96
- opts.on('-x', '--expunge=REGEX',
97
- 'Expung a regexp from all filenames'
98
- ) { |val| options.expunge = val }
104
+ opts.separator 'REGEX-REPLACE:'
105
+
106
+ opts.on('-x', '--expunge [REGEX]',
107
+ "Expung a regexp from all filenames. If a REGEX is
108
+ #{desc_pad}not specified, it searches the current directory's
109
+ #{desc_pad}filenames for a common prefix that can be removed."
110
+ ) do |val|
111
+ if val.nil?
112
+ options.expunge_common_prefix!
113
+ else
114
+ options.expunge = val
115
+ end
116
+ end
99
117
 
100
118
  opts.on('-r', '--replace=STRING',
101
- 'Replace expunged text with'
119
+ 'Replace expunged text with the given STRING'
102
120
  ) { |val| options.mendstr = val }
103
121
 
104
122
  opts.separator ''
105
- opts.separator ' COLLECTIONS:'
123
+ opts.separator 'COLLECTIONS:'
106
124
 
107
125
  opts.on('-f', '--full',
108
126
  'All filters are turned on!'
109
127
  ) do
110
- Fixnames::Option::FLAG_FILTERS.each do |f|
111
- options.send(f, true)
112
- end
128
+ options.all_flags = true
129
+ end
130
+
131
+ opts.on('-M', '--max-autofix',
132
+ "All of --full plus standard options elsewhere.
133
+ #{desc_pad}Should be mostly safe, as we do not clobber fixes
134
+ #{desc_pad}when renaming, but could still be dangerous!"
135
+ ) do
136
+ options.all_flags = true
137
+ options.expunge_common_prefix! if options.expunge.nil?
113
138
  end
114
139
 
115
140
  opts.separator ''
116
- opts.separator ' META:'
141
+ opts.separator 'META:'
117
142
 
118
143
  opts.on('-p', '--pretend',
119
144
  'Pretend to run; no filesystem changes are made'
@@ -144,5 +169,3 @@ filelist = ARGV
144
169
  filelist = Dir['*'] if ARGV.length < 1
145
170
 
146
171
  Fixnames::FixFile.fix_list! filelist, options
147
-
148
-
data/bin/fixnames CHANGED
@@ -20,12 +20,17 @@ end
20
20
  optparse = OptionParser.new do |opts|
21
21
  opts.banner = $banner
22
22
  opts.define_head "Usage: #{$0} [options] <file> [<file> ... ]"
23
+ opts.summary_width = 24
24
+ opts.summary_indent = ' '
25
+
26
+ desc_pad = ' ' * (opts.summary_width + 3)
23
27
 
24
28
  opts.separator ''
25
- opts.separator ' DIRECTORIES:'
29
+ opts.separator 'DIRECTORIES:'
26
30
 
27
31
  opts.on('-g', '--glob=GLOB_STRING',
28
- 'Filename glob inside each directory (default: #{options[:glob]})'
32
+ "Filename glob to use inside each directory for when
33
+ #{desc_pad}we are left to ourself. Default: #{options.dir_glob}"
29
34
  ) { |val| options.dir_glob = val }
30
35
 
31
36
  opts.on('-R', '--[no-]recursive',
@@ -33,7 +38,7 @@ optparse = OptionParser.new do |opts|
33
38
  ) { |val| options.recursive = val }
34
39
 
35
40
  opts.separator ''
36
- opts.separator ' FILTERS:'
41
+ opts.separator 'FILTERS:'
37
42
 
38
43
  opts.on('-A', '--[no-]hack_and',
39
44
  'Replace "&" with "_and_"'
@@ -52,11 +57,14 @@ optparse = OptionParser.new do |opts|
52
57
  ) { |val| options.brackets = val }
53
58
 
54
59
  opts.on('-k', '--[no-]checksums',
55
- 'Trims [0A1B2C3D] CRC32 checksums from names. ( [] or () )'
60
+ "Trims [0A1B2C3D] CRC32 bracket-wrapped checksums
61
+ #{desc_pad}from names, when wrapped with square brackes []
62
+ #{desc_pad}or round parens ()"
56
63
  ) { |val| options.checksums = val }
57
64
 
58
65
  opts.on('-d', '--[no-]dots',
59
- 'Trims excessive dots from files (before the .extention)'
66
+ 'Trims excessive dots from files
67
+ (before the .extention)'
60
68
  ) { |val| options.fix_dots = val }
61
69
 
62
70
  opts.on('-D', '--[no-]dashes',
@@ -72,10 +80,11 @@ optparse = OptionParser.new do |opts|
72
80
  ) { |val| options.lowercase = val }
73
81
 
74
82
  opts.separator ''
75
- opts.separator ' CHARACTERS:'
83
+ opts.separator 'CHARACTERS:'
76
84
 
77
- opts.on('-w', '--whitespace=CHARLIST',
78
- "Characters to treat as whitespace, to be replaced with underscores."
85
+ opts.on('-w', '--whitespace=CHARS',
86
+ "Characters to treat as whitespace, to be
87
+ #{desc_pad}replaced with underscores."
79
88
  ) { |val| options.whitespace = val }
80
89
 
81
90
  opts.on('-W', '--no-whitespace',
@@ -83,7 +92,8 @@ optparse = OptionParser.new do |opts|
83
92
  ) { options.whitespace = nil }
84
93
 
85
94
  opts.on('-s', '--strip=CHARLIST',
86
- "Characters to strip from names. default: #{options.charstrip}"
95
+ "Individual characters to strip from names.
96
+ #{desc_pad}Default: #{options.charstrip}"
87
97
  ) { |val| options.charstrip = val }
88
98
 
89
99
  opts.on('-S', '--no-strip',
@@ -91,29 +101,44 @@ optparse = OptionParser.new do |opts|
91
101
  ) { options.charstrip = nil }
92
102
 
93
103
  opts.separator ''
94
- opts.separator ' REGEX-REPLACE:'
95
-
96
- opts.on('-x', '--expunge=REGEX',
97
- 'Expung a regexp from all filenames'
98
- ) { |val| options.expunge = val }
104
+ opts.separator 'REGEX-REPLACE:'
105
+
106
+ opts.on('-x', '--expunge [REGEX]',
107
+ "Expung a regexp from all filenames. If a REGEX is
108
+ #{desc_pad}not specified, it searches the current directory's
109
+ #{desc_pad}filenames for a common prefix that can be removed."
110
+ ) do |val|
111
+ if val.nil?
112
+ options.expunge_common_prefix!
113
+ else
114
+ options.expunge = val
115
+ end
116
+ end
99
117
 
100
118
  opts.on('-r', '--replace=STRING',
101
- 'Replace expunged text with'
119
+ 'Replace expunged text with the given STRING'
102
120
  ) { |val| options.mendstr = val }
103
121
 
104
122
  opts.separator ''
105
- opts.separator ' COLLECTIONS:'
123
+ opts.separator 'COLLECTIONS:'
106
124
 
107
125
  opts.on('-f', '--full',
108
126
  'All filters are turned on!'
109
127
  ) do
110
- Fixnames::Option::FLAG_FILTERS.each do |f|
111
- options.send(f, true)
112
- end
128
+ options.all_flags = true
129
+ end
130
+
131
+ opts.on('-M', '--max-autofix',
132
+ "All of --full plus standard options elsewhere.
133
+ #{desc_pad}Should be mostly safe, as we do not clobber fixes
134
+ #{desc_pad}when renaming, but could still be dangerous!"
135
+ ) do
136
+ options.all_flags = true
137
+ options.expunge_common_prefix! if options.expunge.nil?
113
138
  end
114
139
 
115
140
  opts.separator ''
116
- opts.separator ' META:'
141
+ opts.separator 'META:'
117
142
 
118
143
  opts.on('-p', '--pretend',
119
144
  'Pretend to run; no filesystem changes are made'
@@ -144,5 +169,3 @@ filelist = ARGV
144
169
  filelist = Dir['*'] if ARGV.length < 1
145
170
 
146
171
  Fixnames::FixFile.fix_list! filelist, options
147
-
148
-
data/fixnames.gemspec CHANGED
@@ -4,20 +4,18 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{fixnames}
8
- s.version = "0.3.0"
7
+ s.name = "fixnames"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Brent Sanders}]
12
- s.date = %q{2011-10-04}
13
- s.description = %q{Cleans up filenames so they can easily be used
14
- in scripts, without annoyances such as spaces or other bad characters}
15
- s.email = %q{git@thoughtnoise.net}
16
- s.executables = [%q{fixnames}, %q{fixdirs}]
11
+ s.authors = ["Brent Sanders"]
12
+ s.date = "2012-02-26"
13
+ s.description = "Cleans up filenames so they can easily be used\nin scripts, without annoyances such as spaces or other bad characters"
14
+ s.email = "git@thoughtnoise.net"
15
+ s.executables = ["fixnames", "fixdirs"]
17
16
  s.extra_rdoc_files = [
18
17
  "LICENSE.txt",
19
- "README.md",
20
- "README.rdoc"
18
+ "README.md"
21
19
  ]
22
20
  s.files = [
23
21
  ".document",
@@ -25,9 +23,7 @@ in scripts, without annoyances such as spaces or other bad characters}
25
23
  "COPYING",
26
24
  "LICENSE.txt",
27
25
  "README.md",
28
- "README.rdoc",
29
26
  "Rakefile",
30
- "VERSION",
31
27
  "bin/fixdirs",
32
28
  "bin/fixnames",
33
29
  "fixnames.gemspec",
@@ -59,11 +55,11 @@ in scripts, without annoyances such as spaces or other bad characters}
59
55
  "test/test_semicolon.rb",
60
56
  "test/test_whitespace.rb"
61
57
  ]
62
- s.homepage = %q{http://github.com/pdkl95/fixnames}
63
- s.licenses = [%q{MIT}]
64
- s.require_paths = [%q{lib}]
65
- s.rubygems_version = %q{1.8.5}
66
- s.summary = %q{Filename cleanup for script compatability}
58
+ s.homepage = "http://github.com/pdkl95/fixnames"
59
+ s.licenses = ["MIT"]
60
+ s.require_paths = ["lib"]
61
+ s.rubygems_version = "1.8.11"
62
+ s.summary = "Filename cleanup for script compatability"
67
63
 
68
64
  if s.respond_to? :specification_version then
69
65
  s.specification_version = 3
@@ -1,3 +1,5 @@
1
+ require 'abbrev'
2
+
1
3
  module Fixnames
2
4
  class Option
3
5
  # filters that MUST run early
@@ -159,5 +161,25 @@ module Fixnames
159
161
  # if set, we just pretend to work, and skip the final
160
162
  # move command, so the filesystem is never altered
161
163
  mkopt :pretend, [TrueClass, FalseClass], false
164
+
165
+
166
+ #################################################################
167
+
168
+ def all_flags=(val)
169
+ Fixnames::Option::FLAG_FILTERS.each do |f|
170
+ send(f, val)
171
+ end
172
+ end
173
+
174
+ def expunge_common_prefix!
175
+ STDERR.puts "DWIM-WARN: No REGEX was given to -x/--expunge"
176
+ pfx = Dir['*'].abbrev.keys.min_by{ |k| k.length }.chop
177
+ if pfx && pfx.length > 0
178
+ STDERR.puts "DWIM-WARN: Will expunge the common prefix: %r{^#{pfx}}"
179
+ self.expunge = "^#{pfx}"
180
+ else
181
+ raise RuntimeError, 'ERROR: No common prefixes found in $PWD/*'
182
+ end
183
+ end
162
184
  end
163
185
  end
@@ -1,7 +1,7 @@
1
1
  class Fixnames
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 3
4
+ MINOR = 4
5
5
  PATCH = 0
6
6
  BUILD = nil
7
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixnames
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-04 00:00:00.000000000 Z
12
+ date: 2012-02-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: term-ansicolor
16
- requirement: &5016780 !ruby/object:Gem::Requirement
16
+ requirement: &10980100 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *5016780
24
+ version_requirements: *10980100
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yard
27
- requirement: &5012940 !ruby/object:Gem::Requirement
27
+ requirement: &10979300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.6.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *5012940
35
+ version_requirements: *10979300
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &5010180 !ruby/object:Gem::Requirement
38
+ requirement: &10978520 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.3.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *5010180
46
+ version_requirements: *10978520
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &5057860 !ruby/object:Gem::Requirement
49
+ requirement: &10977640 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *5057860
57
+ version_requirements: *10977640
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &5056700 !ruby/object:Gem::Requirement
60
+ requirement: &10976840 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *5056700
68
+ version_requirements: *10976840
69
69
  description: ! 'Cleans up filenames so they can easily be used
70
70
 
71
71
  in scripts, without annoyances such as spaces or other bad characters'
@@ -77,16 +77,13 @@ extensions: []
77
77
  extra_rdoc_files:
78
78
  - LICENSE.txt
79
79
  - README.md
80
- - README.rdoc
81
80
  files:
82
81
  - .document
83
82
  - .rspec
84
83
  - COPYING
85
84
  - LICENSE.txt
86
85
  - README.md
87
- - README.rdoc
88
86
  - Rakefile
89
- - VERSION
90
87
  - bin/fixdirs
91
88
  - bin/fixnames
92
89
  - fixnames.gemspec
@@ -138,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
135
  version: '0'
139
136
  requirements: []
140
137
  rubyforge_project:
141
- rubygems_version: 1.8.5
138
+ rubygems_version: 1.8.11
142
139
  signing_key:
143
140
  specification_version: 3
144
141
  summary: Filename cleanup for script compatability
data/README.rdoc DELETED
@@ -1,17 +0,0 @@
1
- = fixnames
2
-
3
- Description goes here.
4
-
5
- == Note on Patches/Pull Requests
6
-
7
- * Fork the project.
8
- * Make your feature addition or bug fix.
9
- * Add tests for it. This is important so I don't break it in a
10
- future version unintentionally.
11
- * Commit, do not mess with rakefile, version, or history.
12
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
- * Send me a pull request. Bonus points for topic branches.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2010 Brent Sanders. See LICENSE for details.
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.1