Skip to content

Instantly share code, notes, and snippets.

@tbmatuka
Created April 13, 2021 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbmatuka/8f5aaf3ac2d0fe2fb156e503c6e4efe2 to your computer and use it in GitHub Desktop.
Save tbmatuka/8f5aaf3ac2d0fe2fb156e503c6e4efe2 to your computer and use it in GitHub Desktop.
#!/bin/bash
userName="John Doe"
emails=(
"john@doe.com"
"john.doe@freelance.com"
"john.doe@acme.com"
)
if [[ $1 =~ ^[1-9][0-9]*$ ]]
then
key=$1
realKey=$(($key - 1))
email="${emails[${realKey}]}"
if [ -z "${email}" ]
then
echo "User with key ${key} does not exist"
exit 1
fi
git config --global user.name "${userName}"
git config --global user.email "${email}"
echo "Changed user to: $(git config user.name) <$(git config user.email)>"
else
realFirstKey="$(echo ${!emails[@]} | grep -Eo '^[0-9]+')"
realLastKey="$(echo ${!emails[@]} | grep -Eo '[0-9]+$')"
firstKey=$(($realFirstKey + 1))
lastKey=$(($realLastKey + 1))
echo "Usage: $0 [${firstKey}-${lastKey}]"
for realKey in ${!emails[@]}
do
key=$(($realKey + 1))
email="${emails[${realKey}]}"
echo " ${key} - ${userName} <${email}>"
done
echo "Current user: $(git config user.name) <$(git config user.email)>"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment