fixnames 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/COPYING ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2006 why the lucky stiff
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Brent Sanders
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ # fixnames
2
+
3
+ Fix filenames to be bash-script safe and easy to type.
4
+
5
+ ## Usage
6
+
7
+ See the {Fixnames::Option} for the various settings.
8
+
9
+ fixnames [options] <files>
10
+ fixdirs [options] <directories>
11
+
12
+ ### examples
13
+
14
+ cleanup a dir:
15
+ fixnames -fvv somedir/*
16
+
17
+ Remove all "`xyzzy`" from filenames:
18
+ fixnames -x xyzzy *
19
+
20
+ Remove all *digits* from filenames and replace them with "`X`":
21
+ fixnames -x \[0-9] -r X *
22
+
23
+
24
+ ## Copyright
25
+
26
+ Copyright (c) 2011 Brent Sanders. See LICENSE.txt for
27
+ further details.
28
+
@@ -0,0 +1,17 @@
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.
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ # -*- mode: ruby -*-
3
+
4
+ require 'rake'
5
+ begin
6
+ require 'psych'
7
+ rescue ::LoadError
8
+ end
9
+ require 'yaml'
10
+
11
+ require 'jeweler'
12
+ require './lib/fixnames/version.rb'
13
+ Jeweler::Tasks.new do |gem|
14
+ gem.name = "fixnames"
15
+ gem.version = Fixnames::Version::STRING
16
+ gem.homepage = "http://github.com/pdkl95/fixnames"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Filename cleanup for script compatability}
19
+ gem.description = %Q{Cleans up filenames so they can easily be used
20
+ in scripts, without annoyances such as spaces or other bad characters}
21
+ gem.email = "git@thoughtnoise.net"
22
+ gem.authors = ["Brent Sanders"]
23
+ gem.executables = ["fixnames", "fixdirs"]
24
+ gem.add_runtime_dependency "term-ansicolor", ">= 1.0.6"
25
+ gem.add_development_dependency "yard", ">= 0.6.0"
26
+ gem.add_development_dependency "rspec", ">= 2.3.0"
27
+ gem.add_development_dependency "jeweler", ">= 1.6.4"
28
+ gem.add_development_dependency "simplecov", ">= 0"
29
+ end
30
+ Jeweler::RubygemsDotOrgTasks.new
31
+
32
+ require 'rspec/core'
33
+ require 'rspec/core/rake_task'
34
+ RSpec::Core::RakeTask.new(:spec) do |spec|
35
+ spec.pattern = FileList['spec/**/*_spec.rb']
36
+ end
37
+
38
+ task :default => :spec
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
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,148 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'rubygems'
4
+
5
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
6
+ require 'fixnames'
7
+
8
+ $fixmode = $0 =~ /dir/ ? :dir : :file
9
+
10
+ options = Fixnames::Option.new
11
+
12
+ case $fixmode
13
+ when :file
14
+ $banner = "Filename fixer to enforce bash-friendly filenames"
15
+ when :dir
16
+ $banner = "Whole-directory filename fixer to enforce bash-friendly filenames"
17
+ options.recursive = true
18
+ end
19
+
20
+ optparse = OptionParser.new do |opts|
21
+ opts.banner = $banner
22
+ opts.define_head "Usage: #{$0} [options] <file> [<file> ... ]"
23
+
24
+ opts.separator ''
25
+ opts.separator ' DIRECTORIES:'
26
+
27
+ opts.on('-g', '--glob=GLOB_STRING',
28
+ 'Filename glob inside each directory (default: #{options[:glob]})'
29
+ ) { |val| options.dir_glob = val }
30
+
31
+ opts.on('-R', '--[no-]recursive',
32
+ 'Recursively descend into directories'
33
+ ) { |val| options.recursive = val }
34
+
35
+ opts.separator ''
36
+ opts.separator ' FILTERS:'
37
+
38
+ opts.on('-A', '--[no-]hack_and',
39
+ 'Replace "&" with "_and_"'
40
+ ) { |val| options.hack_and = val }
41
+
42
+ opts.on('-C', '--[no-]semicolon',
43
+ 'Replace ";" with "-"'
44
+ ) { |val| options.semicolon = val }
45
+
46
+ opts.on('-B', '--[no-]banners',
47
+ 'Trims [FOO] style advert prefixs from the beginning'
48
+ ) { |val| options.banners = val }
49
+
50
+ opts.on('-b', '--[no-]brackets',
51
+ 'Trims (round) or [square] bracket regions'
52
+ ) { |val| options.brackets = val }
53
+
54
+ opts.on('-k', '--[no-]checksums',
55
+ 'Trims [0A1B2C3D] CRC32 checksums from names. ( [] or () )'
56
+ ) { |val| options.checksums = val }
57
+
58
+ opts.on('-d', '--[no-]dots',
59
+ 'Trims excessive dots from files (before the .extention)'
60
+ ) { |val| options.fix_dots = val }
61
+
62
+ opts.on('-D', '--[no-]dashes',
63
+ 'Trims redundant dashes, and leading/trailing dashes'
64
+ ) { |val| options.fix_dashes = val }
65
+
66
+ opts.on('-c', '--[no-]camelcase',
67
+ 'Undo camelCase with underscores. "aB" becomes "a_b"'
68
+ ) { |val| options.camelcase = val }
69
+
70
+ opts.on('-l', '--[no-]lowercase',
71
+ 'Forces all letters to lowercase'
72
+ ) { |val| options.lowercase = val }
73
+
74
+ opts.separator ''
75
+ opts.separator ' CHARACTERS:'
76
+
77
+ opts.on('-w', '--whitespace=CHARLIST',
78
+ "Characters to treat as whitespace, to be replaced with underscores."
79
+ ) { |val| options.whitespace = val }
80
+
81
+ opts.on('-W', '--no-whitespace',
82
+ 'Do not parse any character as whitespace'
83
+ ) { options.whitespace = nil }
84
+
85
+ opts.on('-s', '--strip=CHARLIST',
86
+ "Characters to strip from names. default: #{options.charstrip}"
87
+ ) { |val| options.charstrip = val }
88
+
89
+ opts.on('-S', '--no-strip',
90
+ 'Do not strip any specific characters'
91
+ ) { options.charstrip = nil }
92
+
93
+ 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 }
99
+
100
+ opts.on('-r', '--replace=STRING',
101
+ 'Replace expunged text with'
102
+ ) { |val| options.mendstr = val }
103
+
104
+ opts.separator ''
105
+ opts.separator ' COLLECTIONS:'
106
+
107
+ opts.on('-f', '--full',
108
+ 'All filters are turned on!'
109
+ ) do
110
+ Fixnames::Option::FLAG_FILTERS.each do |f|
111
+ options.send(f, true)
112
+ end
113
+ end
114
+
115
+ opts.separator ''
116
+ opts.separator ' META:'
117
+
118
+ opts.on('-p', '--pretend',
119
+ 'Pretend to run; no filesystem changes are made'
120
+ ) { options.pretend = true }
121
+
122
+ opts.on('-v', '--verbose',
123
+ 'Verbose mode -- repeat for more output'
124
+ ) { options.verbose += 1 }
125
+
126
+ Term::ANSIColor::coloring = STDOUT.isatty
127
+ opts.on('-n', '--no-color',
128
+ 'Suppress ANSI escape codes in the output'
129
+ ) { Term::ANSIColor::coloring = false }
130
+
131
+ opts.on('-h', '--help', 'Show this help message') do
132
+ puts opts
133
+ exit
134
+ end
135
+ end
136
+
137
+ optparse.parse!
138
+
139
+ if options.verbose > 2
140
+ puts "FIXMODE: #{$fixmode}"
141
+ end
142
+
143
+ filelist = ARGV
144
+ filelist = Dir['*'] if ARGV.length < 1
145
+
146
+ Fixnames::FixFile.fix_list! filelist, options
147
+
148
+
@@ -0,0 +1,148 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'rubygems'
4
+
5
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
6
+ require 'fixnames'
7
+
8
+ $fixmode = $0 =~ /dir/ ? :dir : :file
9
+
10
+ options = Fixnames::Option.new
11
+
12
+ case $fixmode
13
+ when :file
14
+ $banner = "Filename fixer to enforce bash-friendly filenames"
15
+ when :dir
16
+ $banner = "Whole-directory filename fixer to enforce bash-friendly filenames"
17
+ options.recursive = true
18
+ end
19
+
20
+ optparse = OptionParser.new do |opts|
21
+ opts.banner = $banner
22
+ opts.define_head "Usage: #{$0} [options] <file> [<file> ... ]"
23
+
24
+ opts.separator ''
25
+ opts.separator ' DIRECTORIES:'
26
+
27
+ opts.on('-g', '--glob=GLOB_STRING',
28
+ 'Filename glob inside each directory (default: #{options[:glob]})'
29
+ ) { |val| options.dir_glob = val }
30
+
31
+ opts.on('-R', '--[no-]recursive',
32
+ 'Recursively descend into directories'
33
+ ) { |val| options.recursive = val }
34
+
35
+ opts.separator ''
36
+ opts.separator ' FILTERS:'
37
+
38
+ opts.on('-A', '--[no-]hack_and',
39
+ 'Replace "&" with "_and_"'
40
+ ) { |val| options.hack_and = val }
41
+
42
+ opts.on('-C', '--[no-]semicolon',
43
+ 'Replace ";" with "-"'
44
+ ) { |val| options.semicolon = val }
45
+
46
+ opts.on('-B', '--[no-]banners',
47
+ 'Trims [FOO] style advert prefixs from the beginning'
48
+ ) { |val| options.banners = val }
49
+
50
+ opts.on('-b', '--[no-]brackets',
51
+ 'Trims (round) or [square] bracket regions'
52
+ ) { |val| options.brackets = val }
53
+
54
+ opts.on('-k', '--[no-]checksums',
55
+ 'Trims [0A1B2C3D] CRC32 checksums from names. ( [] or () )'
56
+ ) { |val| options.checksums = val }
57
+
58
+ opts.on('-d', '--[no-]dots',
59
+ 'Trims excessive dots from files (before the .extention)'
60
+ ) { |val| options.fix_dots = val }
61
+
62
+ opts.on('-D', '--[no-]dashes',
63
+ 'Trims redundant dashes, and leading/trailing dashes'
64
+ ) { |val| options.fix_dashes = val }
65
+
66
+ opts.on('-c', '--[no-]camelcase',
67
+ 'Undo camelCase with underscores. "aB" becomes "a_b"'
68
+ ) { |val| options.camelcase = val }
69
+
70
+ opts.on('-l', '--[no-]lowercase',
71
+ 'Forces all letters to lowercase'
72
+ ) { |val| options.lowercase = val }
73
+
74
+ opts.separator ''
75
+ opts.separator ' CHARACTERS:'
76
+
77
+ opts.on('-w', '--whitespace=CHARLIST',
78
+ "Characters to treat as whitespace, to be replaced with underscores."
79
+ ) { |val| options.whitespace = val }
80
+
81
+ opts.on('-W', '--no-whitespace',
82
+ 'Do not parse any character as whitespace'
83
+ ) { options.whitespace = nil }
84
+
85
+ opts.on('-s', '--strip=CHARLIST',
86
+ "Characters to strip from names. default: #{options.charstrip}"
87
+ ) { |val| options.charstrip = val }
88
+
89
+ opts.on('-S', '--no-strip',
90
+ 'Do not strip any specific characters'
91
+ ) { options.charstrip = nil }
92
+
93
+ 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 }
99
+
100
+ opts.on('-r', '--replace=STRING',
101
+ 'Replace expunged text with'
102
+ ) { |val| options.mendstr = val }
103
+
104
+ opts.separator ''
105
+ opts.separator ' COLLECTIONS:'
106
+
107
+ opts.on('-f', '--full',
108
+ 'All filters are turned on!'
109
+ ) do
110
+ Fixnames::Option::FLAG_FILTERS.each do |f|
111
+ options.send(f, true)
112
+ end
113
+ end
114
+
115
+ opts.separator ''
116
+ opts.separator ' META:'
117
+
118
+ opts.on('-p', '--pretend',
119
+ 'Pretend to run; no filesystem changes are made'
120
+ ) { options.pretend = true }
121
+
122
+ opts.on('-v', '--verbose',
123
+ 'Verbose mode -- repeat for more output'
124
+ ) { options.verbose += 1 }
125
+
126
+ Term::ANSIColor::coloring = STDOUT.isatty
127
+ opts.on('-n', '--no-color',
128
+ 'Suppress ANSI escape codes in the output'
129
+ ) { Term::ANSIColor::coloring = false }
130
+
131
+ opts.on('-h', '--help', 'Show this help message') do
132
+ puts opts
133
+ exit
134
+ end
135
+ end
136
+
137
+ optparse.parse!
138
+
139
+ if options.verbose > 2
140
+ puts "FIXMODE: #{$fixmode}"
141
+ end
142
+
143
+ filelist = ARGV
144
+ filelist = Dir['*'] if ARGV.length < 1
145
+
146
+ Fixnames::FixFile.fix_list! filelist, options
147
+
148
+