Created
February 27, 2024 23:47
-
-
Save theptrk/d99adbd97d9016dd2236b42597c1a253 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
function get_git_repo_url() { | |
# Get the SSH URL from the current Git configuration | |
local ssh_url=$(git config remote.origin.url) | |
# Check if ssh_url is empty | |
if [ -z "$ssh_url" ]; then | |
echo "Not a git repository or no origin set" | |
return 1 | |
fi | |
# Convert SSH URL to HTTPS URL | |
local https_url=$(echo $ssh_url | sed -E 's|git@([^:]+):|https://\1/|') | |
# Optionally, handle the custom SSH alias (e.g., github.com-yourusername) | |
https_url=$(echo $https_url | sed -E 's|github.com-[^/]+/|github.com/|') | |
# Print the HTTPS URL | |
echo $https_url | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment