-
Notifications
You must be signed in to change notification settings - Fork 141
/
forgit.plugin.zsh
executable file
·184 lines (152 loc) · 4.86 KB
/
forgit.plugin.zsh
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
#!/usr/bin/env bash
# MIT (c) Wenxuan Zhang
forgit::error() { printf "%b[Error]%b %s\n" '\e[0;31m' '\e[0m' "$@" >&2; return 1; }
forgit::warn() { 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="$(dirname -- "${BASH_SOURCE[0]}")"
else
forgit::error "Only zsh and bash are supported"
fi
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" ]] && set -o posix
set | awk -F '=' '{ print $1 }' | grep FORGIT_ | while read -r var; do
if ! export | 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
export "$var"
fi
done
unset unexported_vars
[[ -n "$BASH_VERSION" ]] && set +o posix
# register shell functions
forgit::log() {
"$FORGIT" log "$@"
}
forgit::reflog() {
"$FORGIT" reflog "$@"
}
forgit::diff() {
"$FORGIT" diff "$@"
}
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::checkout::file() {
"$FORGIT" checkout_file "$@"
}
forgit::checkout::branch() {
"$FORGIT" checkout_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 "$@"
}
# register aliases
# shellcheck disable=SC2139
if [[ -z "$FORGIT_NO_ALIASES" ]]; then
export forgit_add="${forgit_add:-ga}"
export forgit_reset_head="${forgit_reset_head:-grh}"
export forgit_log="${forgit_log:-glo}"
export forgit_reflog="${forgit_reflog:-grl}"
export forgit_diff="${forgit_diff:-gd}"
export forgit_ignore="${forgit_ignore:-gi}"
export forgit_checkout_file="${forgit_checkout_file:-gcf}"
export forgit_checkout_branch="${forgit_checkout_branch:-gcb}"
export forgit_checkout_commit="${forgit_checkout_commit:-gco}"
export forgit_checkout_tag="${forgit_checkout_tag:-gct}"
export forgit_branch_delete="${forgit_branch_delete:-gbd}"
export forgit_revert_commit="${forgit_revert_commit:-grc}"
export forgit_clean="${forgit_clean:-gclean}"
export forgit_stash_show="${forgit_stash_show:-gss}"
export forgit_stash_push="${forgit_stash_push:-gsp}"
export forgit_cherry_pick="${forgit_cherry_pick:-gcp}"
export forgit_rebase="${forgit_rebase:-grb}"
export forgit_fixup="${forgit_fixup:-gfu}"
export forgit_blame="${forgit_blame:-gbl}"
alias "${forgit_add}"='forgit::add'
alias "${forgit_reset_head}"='forgit::reset::head'
alias "${forgit_log}"='forgit::log'
alias "${forgit_reflog}"='forgit::reflog'
alias "${forgit_diff}"='forgit::diff'
alias "${forgit_ignore}"='forgit::ignore'
alias "${forgit_checkout_file}"='forgit::checkout::file'
alias "${forgit_checkout_branch}"='forgit::checkout::branch'
alias "${forgit_checkout_commit}"='forgit::checkout::commit'
alias "${forgit_checkout_tag}"='forgit::checkout::tag'
alias "${forgit_branch_delete}"='forgit::branch::delete'
alias "${forgit_revert_commit}"='forgit::revert::commit'
alias "${forgit_clean}"='forgit::clean'
alias "${forgit_stash_show}"='forgit::stash::show'
alias "${forgit_stash_push}"='forgit::stash::push'
alias "${forgit_cherry_pick}"='forgit::cherry::pick::from::branch'
alias "${forgit_rebase}"='forgit::rebase'
alias "${forgit_fixup}"='forgit::fixup'
alias "${forgit_blame}"='forgit::blame'
fi