-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashrc_git.sh
More file actions
216 lines (174 loc) · 5.69 KB
/
Copy pathbashrc_git.sh
File metadata and controls
216 lines (174 loc) · 5.69 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/bash
alias editbashgit='${v_or_g} ${yonienv}/bashrc_git.sh'
# alias gitdiff="git difftool --tool=${v_or_g} --no-prompt"
alias gitdiff='git d'
alias gitdiffkdiff3='git difftool --tool=kdiff3 --no-prompt'
alias gitdiffstat='git --no-pager diff --stat'
alias gitlog='git log --name-status'
# alias gitmkhook='gitdir=$(git rev-parse --git-dir); scp -p -P 29418 yonatanc@l-gerrit.mtl.labs.mlnx:hooks/commit-msg ${gitdir}/hooks/'
gitd ()
{
local diff_this_file=${1};
local -a modified_file_list;
modified_file_list=( $(git status -s | awk '/\ M/{print $2}') );
if [ -n "${diff_this_file}" ] ; then
git dv ${diff_this_file};
else
git status -uno;
fi;
complete -W "$(echo ${modified_file_list[@]})" gitd gitdiff;
}
# alias gitdiscardunstaged='git checkout -- .'
alias gitstashunstaged='git stash --keep-index'
alias gitunstageall='git reset HEAD'
gituncommit ()
{
git log -1 --pretty=format:'%H' > .reuse_commit.txt;
echo "saved index ($(cat .reuse_commit.txt)) in .reuse_commit.txt";
git reset --soft HEAD^
}
gitb ()
{
local branch="$1"
# git b | awk '/^\*/{print "\033[32m-->["$2"]\033[0m"} !/^\*/{print " "$1}'
if [ -z ${branch} ] ; then
git b | sed 's/^\*\ /-->\ /g' | awk '/-->/{print "\033[31m" $1 " " $2 "\033[0m"} !/-->/{print " "$1}' | sort -dV
else
git b | sed 's/^\*\ /-->\ /g' | awk '/-->/{print "\033[31m" $1 " " $2 "\033[0m"} !/-->/{print " "$1}' | grep "${branch}" | sort -dV
fi
complete -W "$(git branch)" gitb
}
alias gitwhichbranch="git s | awk '/On branch/{print $4}'"
gitdiscardcached ()
{
local -a discardlist;
local file_to_discard=${1};
if [ -n "${file_to_discard}" ] ; then
echo "git checkout ${file_to_discard}";
git checkout ${file_to_discard};
return;
fi
discardlist=( $(git diff --name-only --cached) );
if [ ${#discardlist[@]} -gt 0 ] ; then
complete -W "$(echo ${discardlist[@]})" gitdiscardcached;
_gitdiscard "${discardlist[@]}"
fi
}
gitdiscardmodified ()
{
local -a discardlist;
local file_to_discard=${1};
if [ -n "${file_to_discard}" ] ; then
echo "git checkout ${file_to_discard}";
git checkout ${file_to_discard};
return;
fi
discardlist=( $(git ls-files -m) );
if [ ${#discardlist[@]} -gt 0 ] ; then
complete -W "$(echo ${discardlist[@]})" gitdiscardmodified gitd;
_gitdiscard "${discardlist[@]}"
fi
}
_gitdiscard ()
{
local ans;
local -a discardlist=( $(echo "${@}") );
# local file_to_discard=${1};
# discardlist=( $(git status -uno -s | awk '{print $2}') );
# discardlist=( $(git ls-files -m) );
# echo "${#discardlist[@]} :${discardlist[@]}"
# if [ -n "${file_to_discard}" ] ; then
# echo "git checkout ${file_to_discard}";
# git checkout ${file_to_discard};
# return;
# fi
if [ ${#discardlist[@]} -gt 0 ] ; then
complete -W "$(echo ${discardlist[@]})" gitdiscardmodified gitdiscardcached;
echo "about to discard "
for i in ${discardlist[@]} ; do
echo -e "\t$i";
done;
read -p "Are you sure [y/N]" ans;
if [ "$ans" == "y" ] ; then
# git status -uno -s | awk '{system("git checkout " $2)}';
echo ${discardlist[@]} | awk '{ print "git checkout "$0; system("git checkout " $0)}';
fi
fi
}
gitapplyPatchList ()
{
start_index=$1
end_index=$2
patch_path=${3:-.}
# for i in $(printf "%04d " $(seq ${start_index} ${end_index})) ; do git am $i*patch ; done
for i in $(printf "%04d " $(seq ${start_index} ${end_index})) ; do
echo -e "\033[1;31mgit am --reject $( ls ${patch_path}/$i*patch )\033[0m";
git am --reject $( ls ${patch_path}/$i*patch ) ;
done
# for i in $(printf "%04d " $(seq ${start_index} ${end_index})) ; do echo "git am $( ls ${patch_path}/$i*patch)" ; done
}
alias gitconfig="${v_or_g} ~/.gitconfig";
# {
# if [ -e /usr/bin/gvim ] ; then
# g ~/.gitconfig
# elif [ -e /usr/bin/vim ] ; then
# v ~/.gitconfig
# else
# echo "you must install vim to see git config file";
# fi
# }
gitviewpatchsidebyside ()
{
local patchfile=$1;
local origfile=$2;
# gvim -y "+vert diffpatch ${patchfile} " ${origfile};
${v_or_g} "+vert diffpatch ${patchfile} " ${origfile};
}
gitcatpatchfile ()
{
local patchfile=$1;
cat $patchfile | colordiff
}
gitcommityoni ()
{
local module=${1};
if [ -n "${module}" ] ; then
sed -i "s/^module/${module}/g" ${yonienv}/git_templates/git_commit_template_yonic;
fi
git config commit.template ${yonienv}/git_templates/git_commit_template_yonic;
git commit;
git config --unset commit.template;
git checkout ${yonienv}/git_templates/git_commit_template_yonic;
}
gitcommitmlx ()
{
local issue=${1};
if [ -n "${issue}" ] ; then
sed -i "s/Issue:.*/Issue: ${issue}/g" ${yonienv}/git_templates/git_commit_mlx_template;
fi
git config commit.template ${yonienv}/git_templates/git_commit_mlx_template;
git commit;
git config --unset commit.template;
}
gitcommitmetadata ()
{
local issue=${1};
if [ -n "${issue}" ] ; then
sed -i "s/Issue:.*/Issue: ${issue}/g" ${yonienv}/git_templates/git_commit_metadata_template;
fi
git config commit.template ${yonienv}/git_templates/git_commit_metadata_template;
git commit;
git config --unset commit.template;
}
gitcheckouttag ()
{
local tag=$1;
new_branch_name=$2;
git checkout -b ${new_branch_name} tags/${tag};
}
gitcommitfixup ()
{
local index=$1;
git commit -m "fixup: ${index}"
}
alias gitconfignopasswd='git config --global credential.helper cache'