-
Notifications
You must be signed in to change notification settings - Fork 6
/
bash-completion-eg.sh
executable file
·307 lines (289 loc) · 8.1 KB
/
bash-completion-eg.sh
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#
# bash completion support for easy Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <[email protected]>
# Copyright (C) 2008-2010 Elijah Newren <[email protected]>
# *Heavily* based on git-completion.sh
# Distributed under the GNU General Public License, version 2.0.
#
# *** IMPORTANT USAGE NOTE ***
# If you are using an old copy of git-completion.sh and you try to complete
# eg commands that the old version of git-completion.sh did not support, you
# may get errors like:
# bash: _git_fetch: command not found
#
# Reasons/rationale:
# This could be fixed by pulling all of git-completion.sh into this file,
# but this would be a heavy maintainence burden. Also, I like common
# bugs being fixed in one place... This only affects a few subcommands,
# so I don't think the trade-off is harsh. Besides, you can always
# download a recent copy of git and just install the git-completion.sh
# file all by itself to fix any such issues.
# *** END USAGE NOTE ***
#
# The contained completion routines provide support for completing:
#
# *) local and remote branch names
# *) local and remote tag names
# *) .git/remotes file names
# *) git 'subcommands'
# *) tree paths within 'ref:path/to/file' expressions
# *) common --long-options
#
# To use these routines (s/git-completion.sh/bash-completion-eg.sh/ in
# instructions below, but make sure git-completion.sh from the
# contrib/completion/ directory of git sources is also in use):
#
# 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
# 2) Added the following line to your .bashrc:
# source ~/.git-completion.sh
#
# 3) You may want to make sure the git executable is available
# in your PATH before this script is sourced, as some caching
# is performed while the script loads. If git isn't found
# at source time then all lookups will be done on demand,
# which may be slightly slower.
#
# 4) Consider changing your PS1 to also show the current branch:
# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
#
# The argument to __git_ps1 will be displayed only if you
# are currently in a git repository. The %s token will be
# the name of the current branch.
#
# *** Maintainence Note ***
# Since this is so heavily based on git-completion.sh, it can be useful
# to run
# diff -u --ignore-space-change bash-completion-eg.sh git-completion.bash
# against a new version of git-completion.bash (under contrib/completion/
# in a copy of the git sources) in order to pick up any new completion
# commands that should be added to this file. The main thing to check in
# such a diff are the differences between the _eg() and _git() functions,
# particularly completion support that exists for subcommands in the latter
# but has no corresponding support in the former.
# *** End Note ***
__eg_commands ()
{
if [ -n "$__eg_commandlist" ]; then
echo "$__eg_commandlist"
return
fi
local i IFS=" "$'\n'
eg help --all | egrep "^ eg" | awk '{print $2}' | sort | uniq
}
__eg_commandlist=
__eg_commandlist="$(__eg_commands 2>/dev/null)"
__eg_topics ()
{
if [ -n "$__eg_topiclist" ]; then
echo "$__eg_topiclist"
return
fi
local i IFS=" "$'\n'
eg help topic | egrep "^[A-Za-z]" | awk '{print $1}' | grep -v "^Topics"
}
__eg_topiclist=
__eg_topiclist="$(__eg_topics 2>/dev/null)"
_eg_commit ()
{
__git_has_doubledash && return
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--cleanup=*)
__gitcomp "default strip verbatim whitespace
" "" "${cur##--cleanup=}"
return
;;
--reuse-message=*)
__gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
return
;;
--reedit-message=*)
__gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
return
;;
--untracked-files=*)
__gitcomp "all no normal" "" "${cur##--untracked-files=}"
return
;;
--*)
__gitcomp "
--all-tracked --bypass-untracked-check --staged --dirty
--author= --signoff --verify --no-verify
--edit --amend --include --only
"
return
esac
COMPREPLY=()
}
_eg_diff ()
{
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--*)
__gitcomp "--staged --unstaged
--cached --stat --numstat --shortstat --summary
--patch-with-stat --name-only --name-status --color
--no-color --color-words --no-renames --check
--full-index --binary --abbrev --diff-filter
--find-copies-harder --pickaxe-all --pickaxe-regex
--text --ignore-space-at-eol --ignore-space-change
--ignore-all-space --exit-code --quiet --ext-diff
--no-ext-diff"
return
;;
esac
__git_complete_file
}
_eg_help ()
{
local i c=1 command
while [ $c -lt $COMP_CWORD ]; do
i="${COMP_WORDS[c]}"
case "$i" in
topic) command="$i"; break ;;
esac
c=$((++c))
done
if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--*)
__gitcomp "--all"
return
;;
esac
__gitcomp "$(__eg_commands) topic"
else
__gitcomp "$(__eg_topics)"
fi
}
_eg_reset ()
{
__git_has_doubledash && return
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--*)
__gitcomp "--working-copy --no-unstaging --merge --mixed --hard --soft --patch"
return
;;
esac
__gitcomp "$(__git_refs)"
}
_eg_revert ()
{
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--*)
__gitcomp "--commit --no-commit --staged --in --since"
return
;;
esac
__git_complete_file
}
_eg_track ()
{
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--*)
__gitcomp "--show --show-all --unset"
return
;;
esac
__git_complete_remote_or_refspec
}
_eg ()
{
local i c=1 command __git_dir
local cur words cword prev
_get_comp_words_by_ref -n =: cur words cword prev
while [ $c -lt $COMP_CWORD ]; do
i="${COMP_WORDS[c]}"
case "$i" in
--git-dir=*) __git_dir="${i#--git-dir=}" ;;
--bare) __git_dir="." ;;
--version|-p|--paginate) ;;
--help) command="help"; break ;;
--translate|--debug) ;;
*) command="$i"; break ;;
esac
c=$((++c))
done
if [ -z "$command" ]; then
case "${COMP_WORDS[COMP_CWORD]}" in
--*) __gitcomp "
--debug
--translate
--paginate
--no-pager
--git-dir=
--bare
--version
--exec-path
--work-tree=
--help
"
;;
*) __gitcomp "$(__eg_commands) $(__git_aliases)" ;;
esac
return
fi
local expansion=$(__git_aliased_command "$command")
[ "$expansion" ] && command="$expansion"
case "$command" in
am) _git_am ;;
add) _git_add ;;
apply) _git_apply ;;
archive) _git_archive ;;
bisect) _git_bisect ;;
bundle) _git_bundle ;;
branch) _git_branch ;;
checkout) _git_checkout ;;
cherry) _git_cherry ;;
cherry-pick) _git_cherry_pick ;;
clean) _git_clean ;;
clone) _git_clone ;;
commit) _eg_commit ;;
config) _git_config ;;
describe) _git_describe ;;
diff) _eg_diff ;;
fetch) _git_fetch ;;
format-patch) _git_format_patch ;;
gc) _git_gc ;;
grep) _git_grep ;;
help) _eg_help ;;
init) _git_init ;;
log) _git_log ;;
ls-files) _git_ls_files ;;
ls-remote) _git_ls_remote ;;
ls-tree) _git_ls_tree ;;
merge) _git_merge;;
mergetool) _git_mergetool;;
merge-base) _git_merge_base ;;
mv) _git_mv ;;
name-rev) _git_name_rev ;;
pull) _git_pull ;;
push) _git_push ;;
rebase) _git_rebase ;;
remote) _git_remote ;;
reset) _eg_reset ;;
revert) _eg_revert ;;
rm) _git_rm ;;
send-email) _git_send_email ;;
shortlog) _git_shortlog ;;
show) _git_show ;;
show-branch) _git_log ;;
stage) _git_add ;;
stash) _git_stash ;;
submodule) _git_submodule ;;
svn) _git_svn ;;
switch) _git_checkout ;;
tag) _git_tag ;;
track) _eg_track ;;
# unstage) COMPREPLY=() ;; ## Already handled by default case
whatchanged) _git_log ;;
*) COMPREPLY=() ;;
esac
}
complete -o bashdefault -o default -o nospace -F _eg eg 2> /dev/null \
|| complete -o default -o nospace -F _eg eg