/
github.sh
56 lines (47 loc) · 1.3 KB
/
github.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#
# for octocats only
#
# modules
msu_require "console"
# module variables
DEPS=
DEFAULT_USERNAME=$(git config --global user.name)
# generate new github tokens
# will be prompted for necessary information
function new_token() {
ask "username [${DEFAULT_USERNAME}]:" USERNAME
[ "${USERNAME}" == "" ] && USERNAME=${DEFAULT_USERNAME}
ask "password:" PASSWORD 1
ask "comment:" COMMENT
DEFAULT_SCOPES="public_repo"
ask "scopes [${DEFAULT_SCOPES}]:" SCOPES
[ "${SCOPES}" == "" ] && SCOPES=${DEFAULT_SCOPES}
SCOPES_STRING=
for scope in ${SCOPES}
do
SCOPES_STRING="${SCOPES_STRING}, \"${scope}\""
done
curl -s \
-u ${USERNAME}:${PASSWORD} \
-X POST https://api.github.com/authorizations \
--data "{\"scopes\": [$(echo ${SCOPES_STRING} | cut -b 2-)], \
\"note\": \"${COMMENT}\"}"
}
# cloning from github
# ${1} - shorthand e.g. GochoMugo/submarine (https://github.com/GochoMugo/submarine)
# or submarine (https://github.com/<your_user>/submarine)
function clone() {
# sometimes we copy paste urls, so try understand such situations
if [[ "${1}" =~ .*github\.com.* ]]
then
git clone "${1}"
return $?
fi
if [[ "${1}" =~ .*/.* ]]
then
git clone https://github.com/${1}.git
else
git clone https://github.com/${DEFAULT_USERNAME}/${1}.git
fi
return $?
}