Skip to content

Instantly share code, notes, and snippets.

@ruslanosipov
Created April 24, 2013 16:31
Show Gist options
  • Save ruslanosipov/5453510 to your computer and use it in GitHub Desktop.
Save ruslanosipov/5453510 to your computer and use it in GitHub Desktop.
Little script that swaps local gitconfig files used in git version 1.7.10 and up (include.path ~/.gitconfig.local)
#!/usr/bin/env sh
# Ruslan Osipov, April 2013
# Little script that swaps local gitconfig files used in git version
# 1.7.10 and up (include.path ~/.gitconfig.local).
#
# Requirements:
# Little set_prompt function from
# https://github.com/ruslanosipov/dotfiles/blob/master/.bashrc
# ~/.gitconfig.local
# ~/.gitconfig.local.switch
# Both .gitconfig files should have user.name section in them
usrswitch() {
if [ ! -f ~/.gitconfig.local ]; then
echo Can\'t find ~/.gitconfig.local! && return 10
fi
if [ ! -f ~/.gitconfig.local.switch ]; then
echo Can\'t find ~/.gitconfig.local.switch! && return 10
fi
# swap .gitconfig.local with .gitconfig.local.switch
cp ~/.gitconfig.local.switch ~/.gitconfig-local-tmp
cp ~/.gitconfig.local ~/.gitconfig.local.switch
cp ~/.gitconfig-local-tmp ~/.gitconfig.local
rm ~/.gitconfig-local-tmp
# display swap result in PS1
user=`cat ~/.gitconfig.local | grep name | awk -F"=" '{print $2}'`
echo $user > ~/.username
set_prompt 4
}
usrswitch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment