Created
March 30, 2012 19:47
-
-
Save 32bitkid/2254403 to your computer and use it in GitHub Desktop.
Basic git pairing utility.
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
# Sample .profile to display the current user/pair in the prompt (replacing user@machine in the prompt) | |
function git_user_name { | |
git config -z user.name | |
} | |
PS1='\[\033]0;$MSYSTEM:\w\007 | |
\033[32m\]$(git_user_name) \[\033[33m\w$(__git_ps1)\033[0m\] | |
$ ' |
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
#!ruby | |
# place in ~/bin | |
# | |
# Basic usage: | |
# | |
# Setting who you are currently paired with: | |
# $ working_with John Doe | |
# | |
# Finding out who you git thinks you are working with: | |
# $ working_with --whom | |
# | |
# Going solo | |
# $ working_with --nobody | |
require 'win32console' | |
require 'term/ansicolor' | |
class Git | |
class Config | |
class Configuration | |
def initialize(env) | |
@env = env | |
end | |
def user_name | |
get(USER_NAME_KEY) | |
end | |
def user_name? | |
true if get(USER_NAME_KEY).strip.empty? | |
end | |
def user_name=(val) | |
if(val.nil? || val.strip.empty?) | |
unset(USER_NAME_KEY) | |
else | |
set(USER_NAME_KEY,val) | |
end | |
end | |
private | |
USER_NAME_KEY = "user.name" | |
def get(key) | |
`git config --#{@env} #{key}`.chomp | |
end | |
def set(key, val) | |
`git config --#{@env} #{key} "#{val}"` | |
end | |
def unset(key) | |
`git config --#{@env} --unset #{key}` | |
end | |
end | |
Local = Configuration.new(:local) | |
Global = Configuration.new(:global) | |
end | |
end | |
def working_alone | |
"\n #{Term::ANSIColor.green Term::ANSIColor.bold Git::Config::Global.user_name} is working alone" | |
end | |
def working_together | |
"\n #{Term::ANSIColor.green Term::ANSIColor.bold Git::Config::Local.user_name} are working as a pair" | |
end | |
case my_pair = ARGV.join(" ") | |
when /^-w$|^--whom?$|^$/ | |
puts Git::Config::Local.user_name? ? working_alone : working_together | |
when /^-n$|^--no\w+$/ | |
Git::Config::Local.user_name = nil | |
puts working_alone | |
else | |
Git::Config::Local.user_name = "#{Git::Config::Global.user_name} & #{my_pair}" | |
puts working_together | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment