Created
April 13, 2021 10:17
-
-
Save tbmatuka/8f5aaf3ac2d0fe2fb156e503c6e4efe2 to your computer and use it in GitHub Desktop.
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 | |
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