Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 21st, 2012  |  syntax: None  |  size: 0.62 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2.  
  3. . /usr/lib/git-core/git-sh-setup
  4.  
  5. lookup () {
  6.   local profile=$1
  7.   local key=$2
  8.  
  9.   git config -z profile.$profile.$key
  10. }
  11.  
  12. switch_id () {
  13.   local profile=$1
  14.   local name="$(lookup $profile name)"
  15.   local email="$(lookup $profile email)"
  16.  
  17.   echo "Using profile $1: $name [$email]"
  18.   git config user.profile "$profile"
  19.   git config user.name "$name"
  20.   git config user.email "$email"
  21. }
  22.  
  23. print_id () {
  24.   local profile="$(git config user.profile)"
  25.   echo "Current profile: $(lookup $profile name) [$(lookup $profile email)]"
  26. }
  27.  
  28. PROFILE="$1"
  29.  
  30. case $PROFILE in
  31.   "")
  32.     print_id
  33.     ;;
  34.   *)
  35.     switch_id $PROFILE
  36.     ;;
  37. esac