-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithubclone
More file actions
executable file
·151 lines (133 loc) · 3.65 KB
/
githubclone
File metadata and controls
executable file
·151 lines (133 loc) · 3.65 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/zsh
NAME=githubclone
VERSION=2.0.0
GIT_CMD="clone"
GIT_REPO=""
GIT_OUT=""
GIT_FULL_COMMAND=("")
NOCONFIRM=false
showHelp()
{
cat <<- EOF
Usage: $NAME [-hvy] <command> <username>( |/)<repository> [<destination>]
-y, --noconfirm do not ask for any confirmation
-h, --help print help document
-v, --version print script version
Examples:
$NAME -y Electron7-7 HelpfulShellScripts
$NAME Electron7-7/HelpfulShellScripts ./some_shell_scripts
$NAME v$VERSION
EOF
}
realpathCheck()
{
realpath --version >/dev/null 2>&1 && return 0
cat <<- EOF
[WARNING]: /usr/bin/realpath not found
An alternative method of normalizing filesystem paths will be used, instead.
This alternative method should work fine but doesn't resolve soft links, so keep
that in mind if you see this warning message appear.
:3
EOF
return -1
}
FillVariables()
{
if [[ "$1" =~ '/' ]]; then
GIT_REPO="$1"
shift
else
GIT_REPO="$1/$2"
shift 2
fi
if [[ -n "$1" ]]; then
realpathCheck && GIT_OUT="$(realpath -s $1)" || GIT_OUT=$(cd "$1"; pwd)
else
GIT_OUT="$(pwd)/${GIT_REPO##*/}"
fi
[[ -e "$GIT_OUT" ]] && { printf "[WARNING]: Output directory already exists! Appending repository name to output.\n"; GIT_OUT+="/${GIT_REPO##*/}" }
}
RunCommand()
{
sleep .05
printf "Executing command: $GIT_FULL_COMMAND\n"
sleep .2
"${GIT_FULL_COMMAND[@]}"
exit 0
}
ChangeOutput()
{
sleep .05
read "OUTPUT_DIR?Enter new output directory: "
realpathCheck && GIT_OUT="$(realpath -s $OUTPUT_DIR)" || GIT_OUT=$(cd "$OUTPUT_DIR"; pwd)
[[ -e "$GIT_OUT" ]] && { printf "[WARNING]: Output directory already exists! Appending repository name to output.\n"; GIT_OUT+="/${GIT_REPO##*/}" }
printf ":: New output directory:\n\t$OUTPUT_DIR\n"
}
ChangeRepo()
{
printf ":: Valid repository syntaxes:\n\tusername/repository\n\tusername repository\n\n"
sleep .05
read "REPO?Enter new repository: "
OLD_REPO_OUT="${GIT_REPO##*/}"
[[ $REPO =~ '/' ]] && GIT_REPO="$REPO" || GIT_REPO="${REPO/ //}"
printf ":: New repository:\n\t$GIT_REPO\n\n"
sleep .05
read "CONFIRM?Change output directory name to match the repository name? [Y/n] "
sleep .05
[[ "$CONFIRM" =~ ^[Yy]$ || -z "$CONFIRM" ]] && { GIT_OUT=${GIT_OUT/$OLD_REPO_OUT/${GIT_REPO##*/}}; printf ":: New output directory:\n\t$GIT_OUT\n" }
}
ChoiceLoop()
{
sleep .05
GIT_FULL_COMMAND=(git "$GIT_CMD" "https://github.com/$GIT_REPO" "$GIT_OUT")
printf ":: Command to be run:\n\t\"$GIT_FULL_COMMAND\"\n"
printf ":: Options:\n\t1) Run command 2) Change output 3) Change repository 4) Cancel\n\n"
read "CHOICE?Make a selection (default=1): "
case "$CHOICE" in
1|)
RunCommand
;;
2)
ChangeOutput
;;
3)
ChangeRepo
;;
4)
printf "Exiting!\n"
sleep .1
exit -1
;;
*)
printf "Unknown choice: \"$CHOICE\"\n"
sleep .05
;;
esac
ChoiceLoop
}
OPTIONS=$(getopt -l "help,version,noconfirm" -o "hvy" -a -- "$@")
eval set -- "$OPTIONS"
while true
do
case "$1" in
-h|--help)
showHelp
exit 0
;;
-v|--version)
printf "$NAME $VERSION\n"
exit 0
;;
-y|--noconfirm)
NOCONFIRM=true
;;
--)
[[ -z "$2" ]] && { showHelp; exit 1 }
shift
FillVariables "$@"
ChoiceLoop
exit 0
;;
esac
shift
done