dotfiles/.local/bin/scripts/git-get

22 lines
724 B
Plaintext
Raw Normal View History

2022-08-21 10:29:51 +00:00
#!/bin/sh -e
# Clones from resolving the arguments and switches into the new directory
2022-08-21 10:29:51 +00:00
# ARGS: see git-repo, all arguments beyond the first three are forwarded to git clone
2021-06-19 19:24:14 +00:00
remote=$(git-repo "$@")
echo "Cloning $remote"
2022-08-04 21:53:53 +00:00
test $1 = https && shift
case $# in
(1) dir=$(basename ${remote%.git});;
2022-07-03 20:33:28 +00:00
(3) test "$3" != "$(git config --get user.name)" &&
prefix=$(echo "$3" | sed "s|\(.\)\b.*$|\1|") &&
case "$2" in
("$prefix"*) ;;
("$(git config --get user.name)") ;;
(*) dir="${prefix}_$2";;
esac;;
esac
2022-08-21 10:29:51 +00:00
case "$4" in (-*|"") cdir="$2";; (*) cdir="$4";; esac
shift $(expr 3 \& $# \> 3 \| $#)
git clone $remote "$@" $dir --recurse-submodules
2022-08-21 10:29:51 +00:00
cd "${dir:-$cdir}"
2022-07-06 08:17:45 +00:00
exec