Skip to content

Instantly share code, notes, and snippets.

@eykanal
Forked from manveru/setup_gitconfig.rb
Created October 31, 2011 21:32
Show Gist options
  • Save eykanal/1329022 to your computer and use it in GitHub Desktop.
Save eykanal/1329022 to your computer and use it in GitHub Desktop.
Create basic .gitconfig file
#!/usr/bin/ruby
gitconfig = File.expand_path("~/.gitconfig")
if File.file?(gitconfig)
puts "#{gitconfig} already exists."
exit 0
end
puts('##',
'## Git stores each entry with your name, email, and a unique identifier.',
'## The following will set up Git with this information, as well as some ',
'## basic settings to make Git easier to use.',
'##',
'')
$stdout.sync = true
print "Enter full name: "
full_name = gets.chomp
print "Enter email address: "
email = gets.chomp
print "Enter full path to preferred diff tool (press \"Enter\" to skip): "
user_difftool = gets.chomp
system("git", "config", "--global", "user.name", full_name)
system("git", "config", "--global", "user.email", email)
system("git", "config", "--global", "color.ui", "auto")
poss_opendiff_loc = ["/usr/bin/opendiff", "/usr/local/bin/opendiff", "/Developer/usr/bin/opendiff"]
opendiff_loc = ''
poss_opendiff_loc.each do |loc|
if File.exists?(loc)
opendiff_loc = loc
break
end
end
difftool = ''
if !user_difftool.empty?
difftool = user_difftool
elsif !opendiff_loc.empty?
difftool = opendiff_loc
end
if !difftool.empty?
system("git", "config", "-global", "merge", difftool)
system("git", "config", "-global", "diff", difftool)
system("git", "config", "-global", "mergetool", difftool)
system("git", "config", "-global", "difftool", difftool)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment