-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_autocomplete
85 lines (83 loc) · 2.33 KB
/
git_autocomplete
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
_gitcomp(){
local cur prev branches
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
branches="$(git branch 2> /dev/null | sed 's/\*//g')"
gitfiles="$(git status -s 2> /dev/null | sed 's/^...//g')"
case ${COMP_CWORD} in
1)
COMPREPLY=($(compgen -W "`_all_git_commands`" -- ${cur}));;
2)
case ${prev} in
checkout)
COMPREPLY=($(compgen -W "$branches" -- ${cur}));;
ad|add|select|pick|discard|di|diff|reset|unadd|preview|pr)
COMPREPLY=($(compgen -W "$gitfiles" -- ${cur}));;
esac;;
*)
case ${COMP_WORDS[1]} in
branch)
COMPREPLY=($(compgen -W "$branches" -- ${cur}));;
esac
esac
}
_all_git_commands(){
# get normal commands
for i in `git help -a|egrep '^ [a-zA-Z0-9]'`; do
# filter out boring stuff
case $i in
*--*) ;;
am) ;;
cat-file) ;;
check-*) ;;
column) ;;
commit-tree) ;;
count-object) ;;
credential*) ;;
daemon) ;;
diff-*) ;;
fast-*) ;;
fetch-*) ;;
fmt-merge-msg) ;;
for-each-ref) ;;
fsck-objects) ;;
hash-object) ;;
http-*) ;;
index-pack) ;;
init-db) ;;
interpret-trailers) ;;
ls-*) ;;
mail*) ;;
merge-*) ;;
mktag) ;;
mktree) ;;
pack-*) ;;
patch-id) ;;
prune*) ;;
quiltimport) ;;
read-tree) ;;
receive-pack) ;;
remote-*) ;;
rerere) ;;
rev-*) ;;
send-pack) ;;
shell) ;;
show-index) ;;
show-ref) ;;
stripspace) ;;
symoblic-ref) ;;
unpack-*) ;;
update-*) ;;
upload*) ;;
var) ;;
verify-*) ;;
write-tree) ;;
*) echo $i;;
esac;
done
# get aliased commands
for i in `git config --name-only --get-regexp "^alias\..*"`; do
echo "${i#alias.}"
done
}
complete -o default -F _gitcomp git