Skip to content

Instantly share code, notes, and snippets.

@midore
Created May 12, 2011 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save midore/968544 to your computer and use it in GitHub Desktop.
Save midore/968544 to your computer and use it in GitHub Desktop.
# 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