From df08c84b07cf8ac48ee124b2616e3fabacb28c89 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Mon, 27 Jun 2022 21:50:29 +0200 Subject: [PATCH] bin/git-get: automatically create prefixes --- .local/bin/scripts/git-get | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.local/bin/scripts/git-get b/.local/bin/scripts/git-get index 4c38809..be9af35 100755 --- a/.local/bin/scripts/git-get +++ b/.local/bin/scripts/git-get @@ -1,7 +1,16 @@ -#!/bin/sh -e +#!/bin/sh -ex # Clones from resolving the arguments and switches into the new directory -# ARGS see git-repo +# ARGS see git-repo, all arguments beyond the first three are forwarded to git-clone remote=$(git-repo "$@") echo "Cloning $remote" -git clone $remote ${@:4} --recurse-submodules -cd "$(test -n "$2" && echo "$2" || basename ${remote%.git})" +case $# in + (1) dir=$(basename ${remote%.git});; + (3) prefix=$(echo "$3" | sed "s|\(.\)\b.*$|\1|") + case "$2" in + ("$prefix"*) ;; + (*) dir="${prefix}_$2";; + esac;; +esac +shift 3 +git clone $remote "$@" $dir --recurse-submodules +cd "${dir:-${4:-$2}}"