@@ -3,8 +3,73 @@ alias k='kubectl'
3
3
alias pods=' kubectl get pods -w'
4
4
alias pod=' kubectl get pods -w'
5
5
6
+ function git_default_branch(){
7
+ git for-each-ref --format=' %(refname:short)' refs/heads/ | grep -xq " main" && echo -n " main" || echo -n " master"
8
+ }
9
+
10
+ function git_init_global(){
11
+ GIT_USER_NAME=$1
12
+ GIT_USER_EMAIL=$2
13
+
14
+ if [[ -z " $GIT_USER_NAME " ]] || [[ -z " $GIT_USER_EMAIL " ]]; then
15
+ echo " enter your git user.name and user.email with parameter 1 and 2"
16
+ return
17
+ fi
18
+
19
+ if [[ ! -f ~ /.ssh/id_rsa.pub ]]; then
20
+ echo " SSH public key not found"
21
+ return
22
+ fi
23
+
24
+ git config --global alias.co checkout
25
+ git config --global alias.chekcout checkout
26
+ git config --global alias.st status
27
+ git config --global alias.br branch
28
+ git config --global alias.cm ' commit -s'
29
+
30
+ # setup name & email
31
+ git config --global user.name " $GIT_USER_NAME "
32
+ git config --global user.email " $GIT_USER_EMAIL "
33
+
34
+ # by default, sign commit using SSH public key
35
+ git config --global user.signingkey " $HOME /.ssh/id_rsa.pub"
36
+ git config --global gpg.format ssh
37
+ git config --global commit.gpgsign true
38
+ }
39
+
40
+ function git_init_repo(){
41
+ if [[ ! -d ./.git/hooks ]]; then
42
+ git init .
43
+ # echo "Current working directory is not a git repository"
44
+ # return
45
+ fi
46
+
47
+ # add auto sign off commit template
48
+ cat << EOF > .git/hooks/prepare-commit-msg
49
+ #!/bin/sh
50
+
51
+ NAME=$( git config user.name)
52
+ EMAIL=$( git config user.email)
53
+
54
+ if [ -z "\$ NAME" ]; then
55
+ echo "empty git config user.name"
56
+ exit 1
57
+ fi
58
+
59
+ if [ -z "\$ EMAIL" ]; then
60
+ echo "empty git config user.email"
61
+ exit 1
62
+ fi
63
+
64
+ git interpret-trailers --if-exists doNothing --trailer \
65
+ "Signed-off-by: \$ NAME <\$ EMAIL>" \
66
+ --in-place "\$ 1"
67
+ EOF
68
+
69
+ }
70
+
6
71
function gsync(){
7
- DEFAULT_BRANCH=$( git for-each-ref --format= ' %(refname:short) ' refs/heads/ | grep -xq " main " && echo -n " main " || echo -n " master " )
72
+ DEFAULT_BRANCH=$( git_default_branch )
8
73
UPSREAM_BRANCH=$1
9
74
if [[ -z " $UPSREAM_BRANCH " ]]; then
10
75
UPSREAM_BRANCH=$DEFAULT_BRANCH
@@ -17,6 +82,27 @@ function gsync(){
17
82
fi
18
83
}
19
84
85
+ function br(){
86
+ BR=$( git --no-pager branch | gum filter --placeholder ' select a branch' )
87
+ if [[ " ${BR: 0: 2} " != ' * ' ]]; then
88
+ git checkout $( echo $BR | tr -d ' ' )
89
+ fi
90
+ }
91
+
92
+ function br_del(){
93
+ BRANCH=$1
94
+ if [[ ! -f " ./.git/refs/heads/$BRANCH " ]]; then
95
+ echo " branch '$BRANCH ' does not exist"
96
+ return
97
+ fi
98
+
99
+ UPSTREAM=$( git for-each-ref --format=' %(upstream:short)' " refs/heads/$BRANCH " )
100
+
101
+ git checkout $( git_default_branch)
102
+ git branch -D " $BRANCH "
103
+ git push $( echo $UPSTREAM | cut -d ' /' -f 1) " $BRANCH " --delete
104
+ }
105
+
20
106
function kuse(){
21
107
CLS=$1
22
108
if [[ ! -z " $CLS " ]]; then
@@ -163,7 +249,7 @@ alias preview-release="$HOME/go/src/github.com/jijiechen/kong-workspace/kong-mes
163
249
alias clera=' clear'
164
250
alias pdos=' pods'
165
251
166
- export PATH=$HOME /go/bin:$HOME /kong-mesh-2.8.1/bin:$HOME /.kuma-dev/kuma-master/bin:$HOME /.local/bin:$PATH
252
+ export PATH=$HOME /go/bin:$HOME /.cargo/bin: $HOME / kong-mesh-2.8.1/bin:$HOME /.kuma-dev/kuma-master/bin:$HOME /.local/bin:$PATH
167
253
if type crcd > /dev/null 2>&1 ; then
168
254
eval $( crc oc-env)
169
255
fi
@@ -176,15 +262,3 @@ export GIT_PERSONAL_ORG=jijiechen
176
262
if [[ -z " $ZSH " ]]; then
177
263
export PS1=' \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ '
178
264
fi
179
-
180
- git config --global alias.co checkout
181
- git config --global alias.chekcout checkout
182
- git config --global alias.st status
183
- git config --global alias.br branch
184
- git config --global alias.cm ' commit -s'
185
- function br(){
186
- BR=$( git --no-pager branch | gum filter --placeholder ' select a branch' )
187
- if [[ " ${BR: 0: 2} " != ' * ' ]]; then
188
- git checkout $( echo $BR | tr -d ' ' )
189
- fi
190
- }
0 commit comments