Q:

Automatically include repo owner's name when cloning

I clone repos from many different sources. Sometimes it can be confusing who was the source of one of these repos that all sit in my git folder. To fix this I have started manually creating a subfolder with the repo owner's name and then cloning in that subfolder. Is there a way to do this automatically? To have git read the owners name and then clone into /?

A:

git clone takes an optional second argument for a destination:
git clone https://github.com/username/repo username-repo
which you could automate with a shell script for some recognizable providers, something like:
github-clone() {
    local dest="$(printf %s "$1" | sed -n 's#^.*[/:]\([[:alnum:]-]\+\)/\([[:alnum:]-]\+\)\(\.git\)\?$#\1-\2#p')"
    if [[ -z "$dest" ]]; then
        git clone "$1"
    else
        git clone "$1" "$dest"
    fi
}

$ github-clone https://github.com/username/repo
Cloning into 'username-repo'...

