-
Notifications
You must be signed in to change notification settings - Fork 2
/
bash_completion
84 lines (84 loc) · 2.07 KB
/
bash_completion
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
#!/bin/bash
list_branches() {
git for-each-ref refs/heads --format="%(refname:short)"
}
list_tracked() {
git ls-tree HEAD | grep blob | awk '{print $4}';
git ls-tree HEAD | grep tree | awk '{print $4"/"}';
}
list_untracked() {
git ls-files --exclude-standard --other --directory --no-empty-directory
}
list_modified() {
git ls-files --modified
}
list_staged() {
git diff --name-only --relative --cached
}
list_tags() {
git tag
}
list_remotes() {
git remote
}
_get_complete()
{
# Available variables:
# COMP_LINE COMP_POINT COMP_KEY COMP_TYPE COMP_WORDS COMP_CWORD
# $1 : name of command whose arguments are being completed
# $2 : the word being completed
# $3 : the word preceding the word being completed
case ${COMP_CWORD} in
1)
commands="+ - = ! @ # ? ^ \
clone fetch push remote \
add rm ignore stage unstage reset commit uncommit branch rmbranch tag untag \
branches status diff log review \
squash subrepo submodule"
COMPREPLY=( $(compgen -W "${commands}" "$2") )
;;
2)
compopt -o nospace
#case "$3" in
case "${COMP_WORDS[1]}" in
# <branch>
'@' | branch | rmbranch | fetch)
COMPREPLY=( $(compgen -W "$(list_branches)" "$2") )
;;
# <modified path>
'=' | stage | reset)
COMPREPLY=( $(compgen -W "$(list_modified)" "$2") )
;;
# <staged path>
unstage)
COMPREPLY=( $(compgen -W "$(list_staged)" "$2") )
;;
# <tracked path>
'-' | rm)
COMPREPLY=( $(compgen -W "$(list_tracked)" "$2") )
;;
# <ref>
diff)
COMPREPLY=( $(compgen -W "$(list_tracked)" -W "STAGE" -W "HEAD" "$2") )
;;
# <untracked path>
'+' | add | ignore)
compopt -o nospace
COMPREPLY=( $(compgen -W "$(list_untracked)" "$2") )
;;
esac
;;
3)
case "${COMP_WORDS[COMP_CWORD-2]}" in
diff)
compopt -o nospace
COMPREPLY=( $(compgen -W "$(list_tracked)" "$2") )
;;
esac
;;
*)
COMPREPLY=()
;;
esac
}
complete -F _get_complete g