Created
May 12, 2011 13:58
-
-
Save midore/968544 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
# -------------------- | |
# backup.rb | |
# Ruby 1.8.7 Mac OS X 10.6.7 | |
# -------------------- | |
require 'pathname' | |
module HomeDir | |
def selectfiles | |
@home.children.each{|x| | |
next unless x.readable? | |
next if @@standard.index(x.basename.to_s) | |
f, @src = x.basename.to_s, x.realpath.to_s | |
f.match(/^\./) ? fname = "dot#{f}" : fname = f | |
@dst = File.join(@dir, fname) | |
@opt.nil? ? onlyls : cpall | |
} | |
end | |
def onlyls | |
print "#{@src} #{@dst}\n" | |
end | |
def cpall | |
system("cp -a #{@src} #{@dst}") | |
end | |
@@standard = [ | |
# Standard | |
"Music", "Public", "Sites", "Downloads", | |
"Library", "Documents", "Movies", | |
"Pictures", "Desktop", "Applications", | |
".fseventsd", ".Spotlight-V100", ".TemporaryItems", | |
".Trash", ".Trashes", | |
".CFUserTextEncoding", ".DS_Store", ".bash_history", | |
".irb_history", ".ri", | |
] | |
end | |
class BackUp | |
def initialize | |
@opt = ARGV[1] | |
@dir = Pathname.new(ARGV[0]) | |
@home = Pathname.new(ENV['HOME']) | |
exit unless File.exist?(@dir) | |
exit if @home.realpath == @dir.realpath | |
(print "Error: Not Writable. \n"; exit) unless @dir.writable? | |
end | |
def run | |
# p self;exit | |
selectfiles | |
end | |
self.send(:include, HomeDir) | |
end | |
BackUp.new.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment