Created
January 23, 2010 04:14
-
-
Save robertsosinski/284420 to your computer and use it in GitHub Desktop.
Modification of Bryan Helmkamp's pair script
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 ruby | |
require 'yaml' | |
PAIR_EMAIL = "paired@developers.local" | |
AUTHORS = YAML.load(`cat ~/.pair.yml`) | |
unless File.exists?(".git") | |
puts "This doesn't look like a git repository." | |
exit 1 | |
end | |
authors = ARGV.map do |initials| | |
if AUTHORS[initials.downcase] | |
AUTHORS[initials.downcase] | |
else | |
puts "Couldn't find author name for initials: #{initials}" | |
exit 1 | |
end | |
end | |
if authors.any? | |
if authors.size == 1 | |
authors = authors.first | |
elsif authors.size == 2 | |
authors = authors.join(" and ") | |
else | |
authors = authors[0..-2].join(", ") + " and " + authors.last | |
end | |
`git config user.name '#{authors}'` | |
`git config user.email '#{PAIR_EMAIL}'` | |
puts "user.name = #{authors}" | |
puts "user.email = #{PAIR_EMAIL}" | |
else | |
`git config user.name 'removing'` # To prevent --remove-section errors when no user config exists | |
`git config --remove-section user` | |
puts "user.name = #{`git config user.name`}" | |
puts "user.email = #{`git config user.email`}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment