-
Notifications
You must be signed in to change notification settings - Fork 0
/
_gitsync
63 lines (57 loc) · 1.55 KB
/
_gitsync
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
#compdef gitsync
#autoload
function _unique-merge-candidates() {
comm -13 \
<(echo $words | tr ' ' '\n' | sed 's|\\~1|~1|g' | sort -u) \
<(_merge-candidates $reporoot/$(_infer-repo-dir) | sed 's|\\~1|~1|g' | sort -u)
}
function _gs-merge() {
local candidates
candidates=($(_unique-merge-candidates))
_describe candidates candidates
}
function _gs-checkout() {
if [ $cur = 2 ]; then
local candidates
candidates=($(_checkout-candidates))
_describe candidates candidates
fi
}
function _gs-fetch-or-push() {
local candidates
candidates=("--all")
if [ $cur = 2 ]; then
_describe candidates candidates
fi
}
function _gitsync() {
local cur
(( cur = CURRENT - 1 ))
if [ $cur = 1 ]; then
_gs_actions=(merge push fetch swap autocommit checkout)
if { git rev-parse --show-toplevel &>/dev/null }; then
if { _gitsync-can-mount }; then
_gs_actions=($_gs_actions "mount")
fi
if { _gitsync-can-dissolve }; then
_gs_actions=($_gs_actions "dissolve")
fi
_gs_actions=($_gs_actions fix-inconsistencies)
else
_gs_actions=(push fetch)
fi
_describe _gs_actions _gs_actions
elif [ $cur -ge 2 ]; then
case $words[2] in
merge)
_gs-merge
;;
checkout)
_gs-checkout
;;
push|fetch)
_gs-fetch-or-push
;;
esac
fi
}