Last active
July 7, 2024 16:07
-
-
Save ooMia/afbae4f3249609e0bf17e4b6c7baa696 to your computer and use it in GitHub Desktop.
Script to get GitHub avatar
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 | |
# Script to get GitHub avatar | |
# Prompt the user for the GitHub username | |
read -p "Enter GitHub username: " username | |
# Make a GET request to the GitHub API to fetch the user's avatar URL | |
# Use awk to extract the avatar_url from the JSON response | |
avatar_url=$(curl -s "https://api.github.com/users/$username" | awk -F '"' '/avatar_url/{print $4}') | |
# Ask the user if they want to download the avatar or just get the URL | |
read -p $'(1) Download the avatar\n(2) Just get the URL\n> ' action | |
if [ "$action" = "1" ]; then | |
# Download the avatar image using the fetched URL | |
curl -s -o "$username.jpg" "$avatar_url" | |
# Display a success message | |
echo "Avatar downloaded successfully!" | |
elif [ "$action" = "2" ]; then | |
# Display the avatar URL | |
echo "Avatar URL: $avatar_url" | |
else | |
echo "Invalid option selected." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment