-
Notifications
You must be signed in to change notification settings - Fork 18
/
mgit-autocomplete.sh
78 lines (70 loc) · 1.5 KB
/
mgit-autocomplete.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
#!/bin/bash
__array_contains () {
local seeking=$1; shift
local in=1
for element; do
if [[ $element == $seeking ]]; then
in=0
break
fi
done
echo $in
}
_mgit()
{
cur=${COMP_WORDS[COMP_CWORD]}
local nocomp="which remove"
if [[ $(mgit ls) != $(cd /;mgit ls) ]]
then
repos=$(mgit ls)
else
repos=()
fi
if [[ ${#COMP_WORDS[@]} -gt 2 ]]
then
if [[ $(__array_contains ${COMP_WORDS[1]} $nocomp) -eq 0 ]]
then
if [[ ${COMP_WORDS[1]} == "remove" ]]
then
complete="$repos"
else
return #fall back to bash file autocomplete or don't return anything
fi
elif [[ $(__array_contains ${COMP_WORDS[1]} $repos) -eq 0 ]]
then
cword=$((${#COMP_WORDS[@]}-1))
words=(git --git-dir=".mgit/${COMP_WORDS[1]}/.git" ${COMP_WORDS[@]:2})
prev=${words[$(($cword-1))]}
COMP_WORDS=${words[@]}
unset COMPREPLY
__git_main
unset words cword prev cur
return
else
complete=""
fi
else
local default=" init
remove
ls
ls-all
ls-uncloned
ls-untracked
ls-double-tracked
ls-tracked
which
ls-modified
status
ls-unpushed
clone
clone-all
clone-release
origin
baseurl
"
__gitcomp "$repos $default" #handles trailing spaces yay!
return
fi
COMPREPLY=( $(compgen -W "$complete" -- $cur) )
}
complete -o bashdefault -o default -o nospace -F _mgit mgit