-
Notifications
You must be signed in to change notification settings - Fork 0
/
fun.sh
40 lines (40 loc) · 907 Bytes
/
fun.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
gh-clone() {
if [ -z "$1" ]
then
cat <<-EOF
# GitHub clone repo util
##
# Installation instructions, source and license available here:
# https://github.com/fibo/gh-clone#gh-clone
##
USAGE: gh-clone [user/]repo
EOF
return 0
fi
GITHUB_DIR=${GITHUB_DIR:-~/github.com}
MY_GITHUB_USER=$(git config --global github.user)
if [ -z "$MY_GITHUB_USER" ]
then
cat <<-EOF
git config --global github.user <MY_GITHUB_USER>
EOF
return 0
fi
GITHUB_USER=$(echo $1 | cut -d / -f1)
REPO_NAME=$(echo $1 | cut -d / -f2)
if [ "$REPO_NAME" == "$GITHUB_USER" ]
then
GITHUB_USER=$MY_GITHUB_USER
fi
TARGET_DIR=$GITHUB_DIR/$GITHUB_USER
mkdir -p $TARGET_DIR
cd $TARGET_DIR
[email protected]:$GITHUB_USER/${REPO_NAME}.git
git clone --recursive $REPO_URL && cd $REPO_NAME
unset GITHUB_DIR
unset GITHUB_USER
unset MY_GITHUB_USER
unset REPO_NAME
unset REPO_URL
unset TARGET_DIR
}