Repository navigation
Expand file tree
/
Copy pathgithub
More file actions
executable file
·175 lines (155 loc) · 6 KB
/
Copy pathgithub
File metadata and controls
executable file
·175 lines (155 loc) · 6 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
# Help
show_help() {
echo "usage: github <command> [<args>]"
echo ""
echo "Extensions github commands are:"
echo "clone <username> <repository> Clone the repository at http://github.com/<username>/<repository>"
echo "clone <repository> Clone your repository at git@github.com/<username>/<repository>"
echo "commit [options] Commit on Github.com with your signed-of-by"
echo "info Give informations contained in your .gitconfig"
echo "page Update your webpages : git push origin 'master:gh-pages' && git pull origin 'master:gh-pages'"
echo "pubkey Give your public RSA public key"
echo "pull Git pull origin master"
echo "push Git push origin master"
echo "tiny <remote> <branch> Only for SMALL projects : git pull <remote> <branch> && git add -A && git commit -s && git push <remote> <branch>"
echo "tiny Only for SMALL projects : git pull origin master && git add -A && git commit -s && git push origin master"
echo "update <remote> <branch> Git pull <remote> <branch> && Git push <remote> <branch>"
echo "update Git pull origin master && Git push origin master"
echo ""
echo "See 'git help' for more information on a git command."
}
# Test if no arguments have been added
if [ $# -lt 1 ]; then
show_help;
exit 1;
fi
# Test the git command
git > /dev/null
if [ $? != 1 ]; then
echo "ERROR - Git is not installed";
exit 2;
fi
# If you want to see all commands
if [ $1 = "help" ]
then #echo "The list of commands:";
show_help;
exit 0;
fi;
# Classical command github clone
if [ $1 = "clone" -a $# = 3 ];
then username=$2; repository=$3; git clone git@github.com:$username/$repository; exit 0;
fi;
# Other command github clone for your repository
if [ $1 = "clone" -a $# = 2 ];
then username=`git config --global github.user`; repository=$2; git clone git@github.com:$username/$repository; exit 0;
fi;
# Classical command github commit with your signed-of-by
if [ $1 = "commit" ]
then git commit -s $2 $3 $4 $5 $6 $7 $8 $9; exit 0;
fi;
# Github update command with branch
if [ $1 = "update" -a $# = 3 ]
then git pull $2 $3 && git push $2 $3; exit 0;
fi;
# Github update command without branch
if [ $1 = "update" ]
then git pull origin master && git push origin master; exit 0;
fi;
# Github update command without branch
if [ $1 = "page" -a $# = 1 ]
then git pull origin 'master:gh-pages' && git push origin 'master:gh-pages'; exit 0;
fi;
# Github tiny command without branch
if [ $1 = "tiny" -a $# = 1 ]
then git pull origin master && git add -A && git commit -s && git push origin master; exit 0;
fi;
# Github tiny command with branch
if [ $1 = "tiny" -a $# = 3 ]
then git pull $2 $3 && git add -A && git commit -s && git push $2 $3; exit 0;
fi;
# Github wizard for the first use
if [ $1 = "setup" ];
then cd ~/.ssh > /dev/null;
if [ $? = 1 ];
then echo -n "You have no SSH keys";
#https://help.github.com/articles/generating-ssh-keys & https://help.github.com/articles/set-up-git
echo -n "What email address did you register on Github?"
read EMAIL;
ssh-keygen -t rsa -C EMAIL;
fi;
echo -n "Now, add this SSH public key to your GitHub account:";
cat ~/.ssh/id_rsa.pub;
echo -n "See: http://help.github.com/articles/generating-ssh-keys#step4"
fi;
# Github config for awesone use
if [ $1 = "setup" ];
then echo -n "First, What's your name?";
read NAME;
git config --global user.name NAME;
echo -n "Now, What's your email?";
read EMAIL;
git config --global user.email EMAIL;
echo -n "Do you wish to configure your API account? [y/n]:"
while read -r -n 1 -s answer; do
if [[ $answer = [YyNn] ]]; then
[[ $answer = [Yy] ]] && retval=0
[[ $answer = [Nn] ]] && retval=1
break
fi
if retval; then
echo -n "[1/2] What's your username?";
read USERNAME;
git config --global github.user USERNAME;
echo -n "[2/2] What's your token?";
read TOKEN;
git config --global github.token TOKEN;
fi;
done
echo -n "Do you wish to cache your credentials, to avoid typing your password everytime? [y/n]:"
while read -r -n 1 -s answer; do
if [[ $answer = [YyNn] ]]; then
[[ $answer = [Yy] ]] && retval=0
[[ $answer = [Nn] ]] && retval=1
break
fi
if retval; then
git config --global credential.helper cache;
echo -n "What's the cache timeout? (in seconds)";
read TIMEOUT;
git config --global credential.helper 'cache --timeout=3600';
fi;
done
echo -n "Do you wish to configure your favorite editor? [y/n]:"
while read -r -n 1 -s answer; do
if [[ $answer = [YyNn] ]]; then
[[ $answer = [Yy] ]] && retval=0
[[ $answer = [Nn] ]] && retval=1
break
fi
if retval; then
echo "What is your favorite editor?"
read EDITOR;
git config --global core.edit EDITOR;
fi;
done
fi;
# Github info command
if [ $1 = "info" ];
then username=`git config --global github.user`; email=`git config --global user.email`; editor=`git config --global core.editor`; name=`git config --global user.name`; token=`git config --global github.token`; cache=`git config --global credential.helper`; pubkey=`cat ~/.ssh/id_rsa.pub`; echo "Github account :" $username; echo "Github email :" $email; echo "Your editor :" $editor; echo "Your name :" $name; echo "Your cache :" $cache; echo "Your API token :" $token; echo "Your public key : \`github pubkey\`" ; exit 0;
fi;
# Github ssh command
if [ $1 = "pubkey" ];
then cat ~/.ssh/id_rsa.pub; exit 0;
fi;
# TODO Github add remote command
# Github pull command
if [ $1 = "pull" -a $# = 1 ];
then git pull origin master; exit 0;
fi;
# Github push command
if [ $1 = "push" -a $# = 1 ];
then git push origin master; exit 0;
fi;
# Classical command git
git $*; exit 0;