Loading...
Bytes is my collection of short-form posts, tips, and things I learn as I build software.
I have several bash scripts that require the remote URL of a Git repository, so a while back I wrote a script to build the URL. I recently rebuilt it with support for SSH host aliases.
#!/bin/bash
# Read the repo base URL from the git config
url=$(git config --get remote.origin.url)
# If the URL does not follow the `git@` format, replace it with the correct one
# from the SSH config.
if [[ $url != "git@"* ]]; then
# Read the host alias from the git config
host=${url/:*/}
# Lookup the real hostname from the SSH config
Now when we call remote-url in our terminal, we should see something like
https://github.com/mskelton/bytes. We’ll see this command used in several
future Bytes!