Skip to content

Instantly share code, notes, and snippets.

@Digital39999
Last active August 28, 2024 15:36
Show Gist options
  • Save Digital39999/e742321b2ff33599345efaf46bd716c9 to your computer and use it in GitHub Desktop.
Save Digital39999/e742321b2ff33599345efaf46bd716c9 to your computer and use it in GitHub Desktop.
#!/bin/bash
confirm_and_apply() {
echo "The following credentials will be applied:"
echo "Name: $1"
echo "Email: $2"
echo
read -p "Do you want to apply these settings? (Y/n): " confirmation
echo
if [[ "$confirmation" == "Y" || "$confirmation" == "y" || "$confirmation" == "" ]]; then
git config user.name "$1"
git config user.email "$2"
echo "Git identity has been set to:"
echo "Name: $1"
echo "Email: $2"
else
echo "Changes not applied."
fi
echo
}
set_anonymous_identity() {
confirm_and_apply "Anonymous Contributor" "[email protected]"
}
set_custom_identity() {
read -p "Enter your name: " custom_name
read -p "Enter your email: " custom_email
confirm_and_apply "$custom_name" "$custom_email"
}
echo "Choose an option:"
echo "1) Use global config"
echo "2) Set both to anonymous"
echo "3) Set custom name and email"
echo
read -p "Enter your choice (1-3): " choice
case $choice in
1)
echo "Using global configuration..."
global_name="$(git config --global user.name)"
global_email="$(git config --global user.email)"
confirm_and_apply "$global_name" "$global_email"
;;
2)
set_anonymous_identity
;;
3)
set_custom_identity
;;
*)
echo "Invalid option. Please choose 1, 2, or 3."
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment