Skip to content

Instantly share code, notes, and snippets.

@sharl
Last active August 29, 2015 14:02
Show Gist options
  • Save sharl/fcddb709276d6bf2924a to your computer and use it in GitHub Desktop.
Save sharl/fcddb709276d6bf2924a to your computer and use it in GitHub Desktop.
git-clone-alter
#!/bin/bash
function usage() {
prog=$(basename $0)
cat <<EOF
Usage: $prog [option] [--] [git clone command]
-n, --name <name>
-e, --email <email>
EOF
exit 1
}
c=$(getopt -o n:e: --long name:,email: -- "$@")
if [ $? != 0 -o $# = 0 ]; then
usage
fi
for opt in $@; do
case $opt in
-n|--name)
name="$2"
shift 2
;;
-e|--email)
email="$2"
shift 2
;;
--)
shift
break
;;
esac
done
if [ -z "$name" ]; then
echo -n "name: "
read name
if [ -z $name ]; then
name="$(git config --global user.name)"
echo use global: $name
fi
fi
if [ -z "$email" ]; then
echo -n "email: "
read email
if [ -z $email ]; then
email="$(git config --global user.email)"
echo use global: $email
fi
fi
git clone $*
if [ $? = 0 ]; then
w=${*:$#}
if [[ $w =~ \.git$ ]]; then
w=${w##*:}
w=${w##*/}
w=${w%.git}
fi
cd $w
if [ $? = 0 ]; then
git config user.name "$name"
git config user.email "$email"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment