From 28e8bdf7f8286bd431b7f3b709e79f3827b31469 Mon Sep 17 00:00:00 2001 From: TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> Date: Wed, 24 Dec 2025 13:54:03 +0900 Subject: updates --- debian/.local/bin/clonerepo | 61 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 debian/.local/bin/clonerepo (limited to 'debian/.local/bin/clonerepo') diff --git a/debian/.local/bin/clonerepo b/debian/.local/bin/clonerepo new file mode 100755 index 0000000..cc1e23f --- /dev/null +++ b/debian/.local/bin/clonerepo @@ -0,0 +1,61 @@ +#!/bin/sh + +usage() { + echo "Clone a git repo in XDG_PUBLICSHARE_DIR if it's set or ~/Public" + echo "" + echo "Usage: ${0##*/} [-b ] [-d ] [-n ] " + echo "" + echo "Options:" + echo " -h : Show this help message" + echo " -b : Specify the branch to clone" + echo " -d : Specify the destination of directory" + echo " -n : Specify the directory name to clone into" + echo "" + echo "Example:" + echo " ${0##*/} -b master # Clone master branch" + echo " ${0##*/} -d ~/.local/bin # Clone the url into ~/.local/bin" + echo " ${0##*/} -n myrepo # Clone url named with myrepo" + exit 1 +} + +# Default values +path="${XDG_PUBLICSHARE_DIR:-$HOME/Public}" + +# Parse options +while getopts ":b:d:n:" opt; do + case $opt in + b) branch="$OPTARG" ;; + d) path="$OPTARG" ;; + n) dirname="$OPTARG" ;; + *) usage ;; + esac +done + +shift $((OPTIND - 1)) + +[ -z "$1" ] && usage + +repo="$1" + +# Validate the URL (supports HTTPS and SSH Git URLs) +if ! echo "$repo" | grep -Eq '^(https://github\.com/[^/]+/[^/]+(\.git)?|git@github\.com:[^/]+/[^/]+(\.git)?)$'; then + echo "Error: Invalid Git URL." + exit 1 +fi + +# Extract the base URL for the repository (removes any trailing .git) +url="$(echo "$repo" | grep -Eo 'https://github.com/[^/]+/[^/]+' | sed 's/\.git$//')" + +# Determine the directory name for cloning +if [ -n "$dirname" ]; then + dest="$path/$dirname" +else + dest="$path/$(basename "$url")" +fi + +# Determine the clone command +if [ -n "$branch" ]; then + git clone --branch "$branch" "$url" "$dest" +else + git clone "$url" "$dest" +fi -- cgit v1.2.3