Skip to content

Instantly share code, notes, and snippets.

@kckrinke
Last active October 24, 2016 17:51
Show Gist options
  • Save kckrinke/51bb64a6328ef0c7028768ed6d90ee8b to your computer and use it in GitHub Desktop.
Save kckrinke/51bb64a6328ef0c7028768ed6d90ee8b to your computer and use it in GitHub Desktop.
Who does GIT think you are?
#!/bin/bash
MODE_SHOW=short
SHOW_MAIL=1
SHOW_NAME=1
while [ $# -gt 0 ]
do
case "$1" in
"-h"|"--help")
echo "usage: $(basename $0) [-h|--help] [-N|--no-name] [-E|--no-email] [-l|--long]"
exit 1
;;
"-E"|"--no-email") SHOW_MAIL=0;;
"-N"|"--no-name") SHOW_NAME=0;;
"-l"|"--long") MODE_SHOW=long;;
*)
echo "ignoring unknown argument: \"$1\""
;;
esac
shift
done
RAW=$(git config --list | egrep '^user\.' | perl -pe 's!^user\.(name|email)\=!${1} !')
NAME=$(echo "${RAW}" | egrep "^name " | awk '{$1="";print $0}' | perl -pe 's!^\s+?!!;')
MAIL=$(echo "${RAW}" | egrep "^email " | awk '{$1="";print $0}' | perl -pe 's!^\s+?!!;')
case "$MODE_SHOW" in
"short")
if [ $SHOW_NAME -eq 1 -a $SHOW_MAIL -eq 1 ]
then
echo "${NAME} <${MAIL}>"
elif [ $SHOW_NAME -eq 1 ]
then
echo "${NAME}"
elif [ $SHOW_MAIL -eq 1 ]
then
echo "${MAIL}"
fi
;;
*)
if [ $SHOW_NAME -eq 1 -a $SHOW_MAIL -eq 1 ]
then
echo "name: ${NAME}"
echo "email: ${MAIL}"
elif [ $SHOW_NAME -eq 1 ]
then
echo "name: ${NAME}"
elif [ $SHOW_MAIL -eq 1 ]
then
echo "email: ${MAIL}"
fi
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment