Last active
December 3, 2025 11:07
-
-
Save hostmaster/370e901eee32cc3bcb99c1ba2c4d7b3b 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
| #!/bin/bash -e | |
| REPO_URL=$1 | |
| ROOT_DIR=$HOME/Code | |
| if [ -z "$REPO_URL" ]; then | |
| echo "Usage: $0 <repo>" | |
| exit 1 | |
| fi | |
| shopt -s extglob | |
| if [[ $REPO_URL =~ ^git ]]; then | |
| REPO=${REPO_URL//git@git?(lab|hub).com:/} | |
| elif [[ $REPO_URL =~ ^https: ]]; then | |
| REPO=${REPO_URL//https:\/\/git?(lab|hub).com\//} | |
| else | |
| echo "Unknown protocol prefix $REPO" | |
| exit 1 | |
| fi | |
| REPO_PATH="${REPO%/*}" | |
| if [ ! -d "$ROOT_DIR/$REPO_PATH" ]; then | |
| mkdir -p "$ROOT_DIR/$REPO_PATH" | |
| fi | |
| REPO_NAME="${REPO##*/}" | |
| REPO_NAME="${REPO_NAME%.git}" | |
| git clone "$REPO_URL" "$ROOT_DIR/$REPO_PATH/$REPO_NAME" | |
| cd "$ROOT_DIR/$REPO_PATH/$REPO_NAME" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment