Created
July 25, 2013 09:13
-
-
Save eacousineau/6078107 to your computer and use it in GitHub Desktop.
glum - Git Lightweight User Management
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
#!/bin/bash | |
# Git Lightweight User Management | |
# To start a new user 'session' | |
# glum USER EMAIL | |
# To end user 'session' | |
# glum | |
glum-broken() { | |
# This shows an error, and replaces git in the current shell as an alias to this function | |
echo "[ git glum: ERROR, set git user with 'glum USER EMAIL' ]" >&2 | |
rm -f /tmp/glum.lock | |
return 1 | |
} | |
glum-info() { | |
echo "[ git glum: $(git config --global user.name) <$(git config --global user.email) ]" | |
} | |
glum() { | |
git config --global user.name > /dev/null && git config --global --remove-section user | |
if test $# -eq 0 | |
then | |
glum-broken || : | |
export PS1='\u@\h:\w$ ' | |
alias git='glum-broken' | |
elif test $# -eq 2 | |
then | |
git config --global user.name "$1" | |
git config --global user.email "$2" | |
unalias git | |
touch /tmp/glum.lock | |
else | |
echo "Usage:" | |
echo " glum USER EMAIL Sets current user" | |
echo " glum Removes current user" | |
fi | |
} | |
if ! test -e /tmp/glum.lock | |
then | |
glum | |
else | |
glum-info | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment