-
Notifications
You must be signed in to change notification settings - Fork 157
Expand file tree
/
Copy pathforgit.plugin.zsh
More file actions
executable file
·254 lines (212 loc) · 7.41 KB
/
forgit.plugin.zsh
File metadata and controls
executable file
·254 lines (212 loc) · 7.41 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/usr/bin/env bash
# MIT (c) Wenxuan Zhang
# all commands are prefixed with command and all built-ins with builtin.
# These shell built-ins prevent the wrong commands getting executed in case a
# user added a shell alias with the same name.
forgit::error() {
command printf "%b[Error]%b %s\n" '\e[0;31m' '\e[0m' "$@" >&2
builtin return 1
}
forgit::warn() { command printf "%b[Warn]%b %s\n" '\e[0;33m' '\e[0m' "$@" >&2; }
# determine installation path
if [[ -n $ZSH_VERSION ]]; then
# shellcheck disable=2277,2296,2299
0="${ZERO:-${${0:#$ZSH_ARGZERO}:-${(%):-%N}}}"
# shellcheck disable=2277,2296,2298
0="${${(M)0:#/*}:-$PWD/$0}"
FORGIT_INSTALL_DIR="${0:h}"
elif [[ -n $BASH_VERSION ]]; then
FORGIT_INSTALL_DIR="$(command dirname -- "${BASH_SOURCE[0]}")"
else
forgit::error "Only zsh and bash are supported"
fi
builtin export FORGIT_INSTALL_DIR
FORGIT="$FORGIT_INSTALL_DIR/bin/git-forgit"
# backwards compatibility:
# export all user-defined FORGIT variables to make them available in git-forgit
unexported_vars=0
# Set posix mode in bash to only get variables, see #256.
[[ -n $BASH_VERSION ]] && builtin set -o posix
builtin set | command awk -F '=' '{ print $1 }' | command grep FORGIT_ | while builtin read -r var; do
if ! builtin export | command grep -q "\(^$var=\|^export $var=\)"; then
if [[ $unexported_vars == 0 ]]; then
forgit::warn "Config options have to be exported in future versions of forgit."
forgit::warn "Please update your config accordingly:"
fi
forgit::warn " export $var"
unexported_vars=$((unexported_vars + 1))
# shellcheck disable=SC2163
builtin export "$var"
fi
done
builtin unset unexported_vars
[[ -n $BASH_VERSION ]] && builtin set +o posix
# register shell functions
forgit::log() {
"$FORGIT" log "$@"
}
forgit::reflog() {
"$FORGIT" reflog "$@"
}
forgit::diff() {
"$FORGIT" diff "$@"
}
forgit::show() {
"$FORGIT" show "$@"
}
forgit::add() {
"$FORGIT" add "$@"
}
forgit::reset::head() {
"$FORGIT" reset_head "$@"
}
forgit::stash::show() {
"$FORGIT" stash_show "$@"
}
forgit::stash::push() {
"$FORGIT" stash_push "$@"
}
forgit::clean() {
"$FORGIT" clean "$@"
}
forgit::cherry::pick() {
"$FORGIT" cherry_pick "$@"
}
forgit::cherry::pick::from::branch() {
"$FORGIT" cherry_pick_from_branch "$@"
}
forgit::rebase() {
"$FORGIT" rebase "$@"
}
forgit::fixup() {
"$FORGIT" fixup "$@"
}
forgit::squash() {
"$FORGIT" squash "$@"
}
forgit::reword() {
"$FORGIT" reword "$@"
}
forgit::checkout::file::from::commit() {
"$FORGIT" checkout_file_from_commit "$@"
}
forgit::checkout::file() {
"$FORGIT" checkout_file "$@"
}
forgit::checkout::branch() {
"$FORGIT" checkout_branch "$@"
}
forgit::switch::branch() {
"$FORGIT" switch_branch "$@"
}
forgit::checkout::tag() {
"$FORGIT" checkout_tag "$@"
}
forgit::checkout::commit() {
"$FORGIT" checkout_commit "$@"
}
forgit::branch::delete() {
"$FORGIT" branch_delete "$@"
}
forgit::revert::commit() {
"$FORGIT" revert_commit "$@"
}
forgit::blame() {
"$FORGIT" blame "$@"
}
forgit::ignore() {
"$FORGIT" ignore "$@"
}
forgit::ignore::update() {
"$FORGIT" ignore_update "$@"
}
forgit::ignore::get() {
"$FORGIT" ignore_get "$@"
}
forgit::ignore::list() {
"$FORGIT" ignore_list "$@"
}
forgit::ignore::clean() {
"$FORGIT" ignore_clean "$@"
}
forgit::attributes() {
"$FORGIT" attributes "$@"
}
forgit::worktree() {
if [[ $# -ne 0 ]]; then
"$FORGIT" worktree "$@"
return $?
fi
local tree
tree=$("$FORGIT" worktree) || return $?
[[ -d $tree ]] && builtin cd "$tree" || return 1
}
forgit::worktree::add() {
local tree
tree=$("$FORGIT" worktree_add "$@") || return $?
[[ -d $tree ]] || return 0
builtin cd "$tree" || return 1
}
forgit::worktree::delete() {
"$FORGIT" worktree_delete "$@"
}
# register aliases
# shellcheck disable=SC2139
if [[ -z $FORGIT_NO_ALIASES ]]; then
builtin export forgit_add="${forgit_add:-ga}"
builtin export forgit_reset_head="${forgit_reset_head:-grh}"
builtin export forgit_log="${forgit_log:-glo}"
builtin export forgit_reflog="${forgit_reflog:-grl}"
builtin export forgit_diff="${forgit_diff:-gd}"
builtin export forgit_show="${forgit_show:-gso}"
builtin export forgit_ignore="${forgit_ignore:-gi}"
builtin export forgit_attributes="${forgit_attributes:-gat}"
builtin export forgit_checkout_file="${forgit_checkout_file:-gcf}"
builtin export forgit_checkout_file_from_commit="${forgit_checkout_file_from_commit:-gcff}"
builtin export forgit_checkout_branch="${forgit_checkout_branch:-gcb}"
builtin export forgit_switch_branch="${forgit_switch_branch:-gsw}"
builtin export forgit_checkout_commit="${forgit_checkout_commit:-gco}"
builtin export forgit_checkout_tag="${forgit_checkout_tag:-gct}"
builtin export forgit_branch_delete="${forgit_branch_delete:-gbd}"
builtin export forgit_revert_commit="${forgit_revert_commit:-grc}"
builtin export forgit_clean="${forgit_clean:-gclean}"
builtin export forgit_stash_show="${forgit_stash_show:-gss}"
builtin export forgit_stash_push="${forgit_stash_push:-gsp}"
builtin export forgit_cherry_pick="${forgit_cherry_pick:-gcp}"
builtin export forgit_rebase="${forgit_rebase:-grb}"
builtin export forgit_fixup="${forgit_fixup:-gfu}"
builtin export forgit_squash="${forgit_squash:-gsq}"
builtin export forgit_reword="${forgit_reword:-grw}"
builtin export forgit_blame="${forgit_blame:-gbl}"
builtin export forgit_worktree="${forgit_worktree:-gwt}"
builtin export forgit_worktree_add="${forgit_worktree_add:-gwa}"
builtin export forgit_worktree_delete="${forgit_worktree_delete:-gwd}"
builtin alias "${forgit_add}"='forgit::add'
builtin alias "${forgit_reset_head}"='forgit::reset::head'
builtin alias "${forgit_log}"='forgit::log'
builtin alias "${forgit_reflog}"='forgit::reflog'
builtin alias "${forgit_diff}"='forgit::diff'
builtin alias "${forgit_show}"='forgit::show'
builtin alias "${forgit_ignore}"='forgit::ignore'
builtin alias "${forgit_attributes}"='forgit::attributes'
builtin alias "${forgit_checkout_file}"='forgit::checkout::file'
builtin alias "${forgit_checkout_file_from_commit}"='forgit::checkout::file::from::commit'
builtin alias "${forgit_checkout_branch}"='forgit::checkout::branch'
builtin alias "${forgit_switch_branch}"='forgit::switch::branch'
builtin alias "${forgit_checkout_commit}"='forgit::checkout::commit'
builtin alias "${forgit_checkout_tag}"='forgit::checkout::tag'
builtin alias "${forgit_branch_delete}"='forgit::branch::delete'
builtin alias "${forgit_revert_commit}"='forgit::revert::commit'
builtin alias "${forgit_clean}"='forgit::clean'
builtin alias "${forgit_stash_show}"='forgit::stash::show'
builtin alias "${forgit_stash_push}"='forgit::stash::push'
builtin alias "${forgit_cherry_pick}"='forgit::cherry::pick::from::branch'
builtin alias "${forgit_rebase}"='forgit::rebase'
builtin alias "${forgit_fixup}"='forgit::fixup'
builtin alias "${forgit_squash}"='forgit::squash'
builtin alias "${forgit_reword}"='forgit::reword'
builtin alias "${forgit_blame}"='forgit::blame'
builtin alias "${forgit_worktree}"='forgit::worktree'
builtin alias "${forgit_worktree_add}"='forgit::worktree::add'
builtin alias "${forgit_worktree_delete}"='forgit::worktree::delete'
fi