public
Description: Ruby on Rails TextMate bundle [Learn it with PeepCode - http://peepcode.com/products/textmate-for-rails-2]
Homepage: http://groups.google.com/group/rubyonrails-textmate
Clone URL: git://github.com/drnic/ruby-on-rails-tmbundle.git
Search Repo:
Click here to lend your support to: ruby-on-rails-tmbundle and make a donation at www.pledgie.com !
ruby-on-rails-tmbundle / script / clean_bundle_file_names
100755 46 lines (39 sloc) 1.257 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env ruby
 
# To be run against files in this bundle to remove any
# non-OS agnostic characters (see BADCHARS list)
# AIM: ease the pain of access to this bundle by WinOS
# machines, for E Text Editor etc.
 
require 'uri'
require 'find'
require 'fileutils'
include FileUtils::Verbose
 
DIR_TO_CLEAN = File.expand_path(File.dirname(__FILE__) + "/../")
BADCHARS = /([<>\|:\*…\"\?\\“”↵—↓↵‘’¬])/
 
def sanitize(f)
  URI.escape(f, BADCHARS).chomp
end
 
def verbose_rename (orig_name, new_name)
  File.rename(orig_name, new_name)
  puts orig_name + " --> " + new_name
end
 
# Sanitize the transit dir
bad_dirs = []
Find.find(DIR_TO_CLEAN) do |f|
  f = File.expand_path(f).sub(DIR_TO_CLEAN, '')
  next if f =~ /\/?\.(git|svn)/
  orig_name = File.basename(f)
  next if orig_name === ( clean_name = sanitize(File.basename(f)) )
  if File.directory? f
    bad_dirs.push(f)
    next
  end
  dirname = File.dirname(f) + "/"
  verbose_rename(dirname + orig_name, dirname + clean_name) unless (orig_name === clean_name)
end
 
puts "Renaming #{bad_dirs.size} dirs..."
bad_dirs.each do |d|
  orig_name = File.basename(d)
  clean_name = sanitize(File.basename(d))
  dirname = File.dirname(d) + "/"
  verbose_rename(dirname + orig_name, dirname + clean_name)
end