🧪 test(_config): add github config option

This commit is contained in:
Eshan Roy
2024-11-20 09:46:34 +05:30
parent 69dddf03b8
commit 9b3242bbf7
2 changed files with 45 additions and 39 deletions

View File

@@ -1,47 +1,53 @@
#!/bin/bash #!/bin/bash
# Author : ESHAN ROY # Author: Eshan Roy <eshan@snigdhaos.org>
# Author URI : https://eshanized.github.io # Author URI : https://eshanized.github.io
# NOTE : Run at your own Risk! set -e
# Function to print GitHub credential configuration options usage() {
print_options() { echo "Usage: ${0##*/} [--email <email>] [--username <username>] [-h]"
echo "🔒 Configure GitHub Credentials:" echo " --email <email> Set the GitHub user email"
echo "1. 📝 Enter GitHub username and password" echo " --username <email> Set the GitHub username"
echo "2. 🔑 Enter GitHub personal access token" echo " -h Display the help message"
echo "3. 📁 Use existing GitHub credentials from ~/.gitconfig" exit 1
} }
# Print options and prompt user to select while [[ "$#" -gt 0 ]]; do
print_options case "$1" in
echo "Enter the number of your chosen option:" --email)
read -r OPTION EMAIL="$2"
shift 2
;;
--username)
USERNAME="$2"
shift 2
;;
-h|--help)
usage
;;
*)
echo "Unknown argument found: $1"
usage
;;
esac
done
# Handle user selection # We will ask prompt for email address if not entered by the user
case $OPTION in if [ -z "$EMAIL" ]; then
1) read -p "Enter your GitHub Email: " EMAIL
echo "Enter your GitHub username:" fi
read -r USERNAME
echo "Enter your GitHub password:"
read -s PASSWORD
git config --global credential.helper store
git config --global credential.username $USERNAME
git config --global credential.password $PASSWORD
;;
2)
echo "Enter your GitHub personal access token:"
read -r TOKEN
git config --global credential.helper store
git config --global credential.username "your-github-username"
git config --global credential.password $TOKEN
;;
3)
echo "Using existing GitHub credentials from ~/.gitconfig"
;;
*)
echo "Invalid option. Exiting."
exit 1;;
esac
echo "GitHub credentials configured successfully! 👍" # We will ask prompt for username if not entered by the user
if [ -z "$USERNAME" ]; then
read -p "Enter your GitHub Username: " USERNAME
fi
# Setting up github config
git config --global user.email "$EMAIL"
git config --global user.name "$USERNAME"
# Get a confirmation message on successful update!
echo "GitHub Configuration setup successfull!"
echo " User Email: $EMAIL"
echo " Username: $USERNAME"

View File