Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 46 lines (39 sloc) 1.257 kb
a89dcbfd » kevin
2008-03-08 This is a merge from the git repository hosted by Dr. Nic
1 #!/usr/bin/env ruby
2
3 # To be run against files in this bundle to remove any
4 # non-OS agnostic characters (see BADCHARS list)
5 # AIM: ease the pain of access to this bundle by WinOS
6 # machines, for E Text Editor etc.
7
8 require 'uri'
9 require 'find'
10 require 'fileutils'
11 include FileUtils::Verbose
12
13 DIR_TO_CLEAN = File.expand_path(File.dirname(__FILE__) + "/../")
14 BADCHARS = /([<>\|:\*…\"\?\\“”↵—↓↵‘’¬])/
15
16 def sanitize(f)
17 URI.escape(f, BADCHARS).chomp
18 end
19
20 def verbose_rename (orig_name, new_name)
21 File.rename(orig_name, new_name)
22 puts orig_name + " --> " + new_name
23 end
24
25 # Sanitize the transit dir
26 bad_dirs = []
27 Find.find(DIR_TO_CLEAN) do |f|
28 f = File.expand_path(f).sub(DIR_TO_CLEAN, '')
29 next if f =~ /\/?\.(git|svn)/
30 orig_name = File.basename(f)
31 next if orig_name === ( clean_name = sanitize(File.basename(f)) )
32 if File.directory? f
33 bad_dirs.push(f)
34 next
35 end
36 dirname = File.dirname(f) + "/"
37 verbose_rename(dirname + orig_name, dirname + clean_name) unless (orig_name === clean_name)
38 end
39
40 puts "Renaming #{bad_dirs.size} dirs..."
41 bad_dirs.each do |d|
42 orig_name = File.basename(d)
43 clean_name = sanitize(File.basename(d))
44 dirname = File.dirname(d) + "/"
45 verbose_rename(dirname + orig_name, dirname + clean_name)
46 end
Something went wrong with that request. Please try again.