I need to insert user credentials into an HTTP string so I can properly populate my git credentials file at ~/.git-credentials
.
These are the three environment variables I have to start with:
user="someUser"
pass="somePass"
uri="http://sometld.org/path/repo.git"
I've been fiddling with awk
, but it will only work with Github style cloning paths (https://github.com/org/repo.git
) and won't work with non-standard paths (https://git.private.org/scm/~user/path/repo.git
):
proto=$(echo $uri | awk -F"/" '{print $1}')
domain=$(echo $uri | awk -F"/" '{print $3}')
repo_path=$(echo $uri | awk -F"/" '{print $4}')
repo_name=$(echo $uri | awk -F"/" '{print $5}')
echo "$proto//$user:$pass@$domain/$repo_path/$repo_name"
# http://someUser:[email protected]/path/repo.git
What is the best/easiest way to insert a username and password into an HTTP string so I can populate my ~/.git-credentials
file?