Skip to content

Instantly share code, notes, and snippets.

@hayeah
Last active December 26, 2022 07:17
Show Gist options
  • Select an option

  • Save hayeah/8dcce661f0461d071147ebdb829a76a9 to your computer and use it in GitHub Desktop.

Select an option

Save hayeah/8dcce661f0461d071147ebdb829a76a9 to your computer and use it in GitHub Desktop.

Revisions

  1. hayeah revised this gist Dec 26, 2022. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions gclone.sh
    Original file line number Diff line number Diff line change
    @@ -33,9 +33,7 @@ gclone() {
    url="$url.git"
    fi

    # Prepend "https://github.com" if the URL doesn't have that prefix

    # If a repository name was not specified as the second argument, extract it from the URL
    # If a clone destination was not specified as the second argument, extract it from the URL
    if [ -z "$2" ]; then
    repo_name=$(echo "$1" | sed -E 's/.*\/([^/]+\/[^/]+).*/\1/')
    else
  2. hayeah created this gist Dec 26, 2022.
    50 changes: 50 additions & 0 deletions gclone.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    : <<COMMENT
    # Clone the repository with the default repository name
    gclone https://github.com/balancer-labs/balancer-v2-monorepo
    # Clone the repository with a custom repository name
    gclone https://github.com/balancer-labs/balancer-v2-monorepo my-custom-name
    # Clone the repository without ".git" suffix
    gclone https://github.com/balancer-labs/balancer-v2-monorepo.git my-custom-name
    # Clone the repository using short form URL
    gclone balancer-labs/balancer-v2-monorepo
    COMMENT

    # gclone https://github.com/balancer-labs/balancer-v2-monorepo
    # gclone https://github.com/balancer-labs/balancer-v2-monorepo.git
    # gclone https://github.com/balancer-labs/balancer-v2-monorepo.git dest
    gclone() {
    # Make sure that a URL was passed as an argument
    if [ -z "$1" ]; then
    echo "Error: No URL specified"
    return 1
    fi

    # Prepend "https://github.com" to the URL if it is in the form "user/repo"
    url="$1"
    if echo "$url" | grep -Eq '^[^/]+/[^/]+$'; then
    url="https://github.com/$url"
    fi

    # Append ".git" to the URL if it doesn't have that suffix
    if ! echo "$url" | grep -Eq '\.git$'; then
    url="$url.git"
    fi

    # Prepend "https://github.com" if the URL doesn't have that prefix

    # If a repository name was not specified as the second argument, extract it from the URL
    if [ -z "$2" ]; then
    repo_name=$(echo "$1" | sed -E 's/.*\/([^/]+\/[^/]+).*/\1/')
    else
    repo_name=$2
    fi

    # remove .git from repo_name
    repo_name=$(echo "$repo_name" | sed -E 's/(.*)\.git/\1/')

    # Clone the repository
    git clone "$url" "$repo_name"
    }