-
Notifications
You must be signed in to change notification settings - Fork 6
/
.git-rc
171 lines (147 loc) · 3.56 KB
/
.git-rc
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
#!/usr/bin/env bash
# Git aliases. source me from .bashrc!
root_dir() {
local dir=
if [ -n "$ZSH_VERSION" ]; then
dir="$(dirname $0)"
else
dir="$(dirname "${BASH_SOURCE[0]}")"
fi
dir="$(cd "$dir" && echo "$PWD")"
echo "$dir"
}
export GIT_HELPERS_HOME="$(root_dir)"
unset -f root_dir
# Function-definition helper used in subdirectories
define_function() {
name="$1"
shift
if [ $# -eq 0 ]; then
echo "Usage: ${FUNCNAME[0]} <alias name> <aliased function> [args...]" >&2
return 1
fi
unalias "$name" &>/dev/null || true
eval "$name() { $@ \"\$@\"; }"
export -f "$name" > /dev/null
}
defn() {
define_function "$@"
}
append_to_path() {
for arg in "$@"; do
if [ -d "$arg" ]; then
export PATH="$PATH:$arg"
fi
done
}
append_subdir_to_path() {
for name in "$@"; do
if [ "${name#/}" != "$name" ]; then
local module="$name"
else
local module="$GIT_HELPERS_HOME/$name"
fi
append_to_path "$module" "$module/aliases"
local gitrc="$module/.git-rc"
if [ -s "$gitrc" ]; then
source "$gitrc"
fi
local gitconfig="$module/.gitconfig"
if [ -s "$gitconfig" ]; then
git-add-global-file include.path "$gitconfig"
fi
done
}
# do this first, because it bootstraps the
append_subdir_to_path config
append_subdir_to_path \
add admin aliases apply \
bisect blame branch \
cat-file checkout check-ignore cherry-pick clone commit conflicts \
describe diff \
fetch \
git-filter-repo \
gist github gitlab graph grep \
help \
lfs log ls \
merge merge-base mv \
nav \
push \
rebase reflog remote reset rev-list revert rm_ \
show stash status submodule \
tag \
version
export o="origin"
export oh="origin/HEAD"
export u="upstream"
export uh="upstream/HEAD"
export DEFAULT_REMOTE="${DEFAULT_REMOTE:-origin}"
export h="HEAD"
# Parent commit aliases
export p="HEAD^"
export pp="HEAD^2"
export p2="HEAD~2"
export p3="HEAD~3"
export p4="HEAD~4"
export p5="HEAD~5"
export p6="HEAD~6"
export p7="HEAD~7"
export p8="HEAD~8"
export p9="HEAD~9"
export p1="HEAD~10"
# Reflog history aliases
export h1="HEAD@{1}"
export h2="HEAD@{2}"
export h3="HEAD@{3}"
export h4="HEAD@{4}"
export h5="HEAD@{5}"
export h6="HEAD@{6}"
export h7="HEAD@{7}"
export h8="HEAD@{8}"
export h9="HEAD@{9}"
export h10="HEAD@{10}"
export h11="HEAD@{11}"
export h12="HEAD@{12}"
export h13="HEAD@{13}"
export h14="HEAD@{14}"
export h15="HEAD@{15}"
export h16="HEAD@{16}"
export h17="HEAD@{17}"
export h18="HEAD@{18}"
export h19="HEAD@{19}"
export h20="HEAD@{20}"
# Stashes
export s0="stash@{0}"
export s1="stash@{1}"
export s2="stash@{2}"
export s3="stash@{3}"
export s4="stash@{4}"
export s5="stash@{5}"
export s6="stash@{6}"
export s7="stash@{7}"
export s8="stash@{8}"
export s9="stash@{9}"
export s10="stash@{10}"
export pr="$DEFAULT_REMOTE/pr"
root_setup() {
local dir="$GIT_HELPERS_HOME"
[ -s "$dir/.gitcomplete" ] && source "$dir/.gitcomplete"
if [ -n "$BASH_VERSION" ]; then
[ -s "$dir/.git-completion.bash" ] && source "$dir/.git-completion.bash"
fi
# Source this repository's `.gitconfig` file from your global `.gitconfig`.
git add-global-config-file "$dir"/config/.gitconfig
export PYTHONPATH="${PYTHONPATH}${PYTHONPATH:+:}$dir/util"
}
root_setup
unset -f root_setup
defn p parallel -k -j+0 --env PATH
git_set_sha() {
export sha="$(git sha)"
}
export -f git_set_sha
alias git-set-sha=git_set_sha
export GLOBAL_GIT_IGNORE_PATH="${GLOBAL_GIT_IGNORE_PATH:-$HOME/global.gitignore}"
if [ -s "$GLOBAL_GIT_IGNORE_PATH" ]; then
git config --global --replace-all core.excludesfile "$GLOBAL_GIT_IGNORE_PATH"
fi