Created
July 12, 2025 06:04
-
-
Save third774/3ec2179196d91c66f54ecda9fed7931c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# git add remote | |
gar() { | |
local url=$(pbpaste) | |
# Validate URL format (basic git remote URL patterns) | |
if [[ ! "$url" =~ ^(https://|git@|ssh://git@).+\.git$ ]] && [[ ! "$url" =~ ^(https://|git@).+/.+$ ]]; then | |
echo "Error: Invalid git remote URL format in clipboard" | |
echo "Expected formats: https://github.com/user/repo.git or [email protected]:user/repo.git" | |
return 1 | |
fi | |
local username=$(echo "$url" | sed 's/.*[:/]\([^/]*\)\/[^/]*$/\1/') | |
if git remote add "$username" "$url" 2>/dev/null; then | |
echo "✓ Added remote '$username' -> $url" | |
else | |
echo "Error: Failed to add remote '$username' (may already exist)" | |
return 1 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment