Created
March 29, 2009 13:59
-
-
Save kdwinter/87403 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby19 | |
# encoding: utf-8 | |
require 'fileutils' | |
module ToGit | |
Gitdir = File.join( ENV['HOME'], 'github/dotfiles' ) | |
class << self | |
Git = lambda { |command, dir| `git --git-dir=#{dir}/.git #{command}` } | |
def copy_and_add( args ) | |
raise 'No file specified' if args.empty? | |
args.each do |file| | |
src = File.expand_path( file ) | |
dst = File.expand_path( File.join( Gitdir, file ) ) | |
FileUtils.cp_r( src, dst ) | |
Git.( "add #{file}", Gitdir ) | |
end | |
end | |
def prompt_for_commit | |
prompt( 'Do you want to commit changes?' ) do | |
print 'Message: ' | |
Git.( "commit -s -m \"#{$stdin.gets.chomp}\"", Gitdir ) | |
end | |
end | |
private | |
def prompt( qst ) | |
qst = qst.strip.capitalize | |
print "#{qst} [y/n] => " | |
$stdin.gets.chomp.to_s == 'y' ? yield : exit | |
end | |
end | |
end | |
ToGit.copy_and_add( ARGV ) | |
ToGit.prompt_for_commit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment