Created
May 7, 2024 11:12
-
-
Save sa-/aac06377c691055ab47612391748f1d2 to your computer and use it in GitHub Desktop.
Clone script to ~/code/[org]/[repo]
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/sh | |
if [ "$#" -ne 1 ]; then | |
echo "Usage: $0 [URL]" | |
exit 1 | |
fi | |
url="$1" | |
repo_name=$(basename "$url" .git) | |
org_name=$(echo "$url" | sed -E 's/^.*[/:]([^/]+)\/[^/]+$/\1/') | |
code_dir="$HOME/code/$org_name" | |
repo_dir="$code_dir/$repo_name" | |
if [ -d "$repo_dir" ]; then | |
echo "Error: $repo_dir already exists." | |
exit 1 | |
fi | |
mkdir -p "$code_dir" | |
git clone "$url" "$repo_dir" | |
echo "Repository cloned to $repo_dir" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment