-
Notifications
You must be signed in to change notification settings - Fork 1
/
bash_completion
93 lines (90 loc) · 3.62 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
85
86
87
88
89
90
91
92
93
_UseFragments () # By convention, the function name
{ # starts with an underscore.
local curr prev cmd
# Pointer to current completion word.
# By convention, it's named "cur" but this isn't strictly necessary.
COMPREPLY=() # Array variable storing the possible completions.
curr=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [ $COMP_CWORD -gt "1" ] ; then
cmd=${COMP_WORDS[1]}
fi
if [ "$cmd" == "follow" ] ; then
case "$curr" in
*)
COMPREPLY=( $( compgen -W '`find . -not -regex ".*/\..*" -not -regex ".*/_fragments.*" -type f | xargs fragments stat -l ? | grep -v "fragments version" | cut -f 2 -`' -- $curr ) );;
esac;
elif [ "$cmd" == "forget" -o "$cmd" == "status" ] ; then
case "$curr" in
*)
COMPREPLY=( $( compgen -W '`$1 status -l AMD\ | grep -v "fragments version" | cut -f 2 -`' -- $curr ) );;
esac;
elif [ "$cmd" == "revert" ] ; then
case "$curr" in
*)
COMPREPLY=( $( compgen -W '`$1 status -l MD | grep -v "fragments version" | cut -f 2 -`' -- $curr ) );;
esac;
elif [ "$cmd" == "commit" ] ; then
case "$curr" in
*)
COMPREPLY=( $( compgen -W '`$1 status -l AM | grep -v "fragments version" | cut -f 2 -`' -- $curr ) );;
esac;
elif [ "$cmd" == "apply" ] ; then
case "$curr" in
-*)
COMPREPLY=( $( compgen -W '-i -a -U --unified' -- $curr ) );;
*)
if [ $COMP_CWORD -gt "2" ] ; then
COMPREPLY=( $( compgen -W '`$1 status -l AMD\ | grep -v "fragments version" | cut -f 2 -`' -- $curr ) );
else
COMPREPLY=( $( compgen -W '`$1 status -l M | grep -v "fragments version" | cut -f 2 -`' -- $curr ) );
fi
esac;
elif [ "$cmd" == "rename" ] ; then
case "$curr" in
*)
if [ $COMP_CWORD -gt "2" ] ; then
COMPREPLY=( $( compgen -f -- $curr | xargs fragments stat -l ? | grep -v "fragments version" | cut -f 2 - | grep -v '_fragments' ) );
else
COMPREPLY=( $( compgen -W '`$1 status -l AMD\ | grep -v "fragments version" | cut -f 2 -`' -- $curr ) );
fi
esac;
elif [ "$cmd" == "diff" ] ; then
case "$curr" in
-*)
COMPREPLY=( $( compgen -W '-U --unified' -- $curr ) );;
*)
COMPREPLY=( $( compgen -W '`$1 status -l AMD | grep -v "fragments version" | cut -f 2 -`' -- $curr ) );;
esac;
elif [ "$cmd" == "fork" ] ; then
case "$curr" in
-*)
COMPREPLY=( $( compgen -W '-U --unified' -- $curr ) );;
*)
COMPREPLY=( $( compgen -W '`$1 status -l AM\ | grep -v "fragments version" | cut -f 2 -`' -- $curr ) );;
esac;
elif [ "$prev" == "fragments" -o "$cmd" == "help" ] ; then
case "$curr" in
a*)
COMPREPLY=( $( compgen -W 'apply' -- $curr ) );;
c*)
COMPREPLY=( $( compgen -W 'commit' -- $curr ) );;
d*)
COMPREPLY=( $( compgen -W 'diff' -- $curr ) );;
h*)
COMPREPLY=( $( compgen -W 'help' -- $curr ) );;
i*)
COMPREPLY=( $( compgen -W 'init' -- $curr ) );;
f*)
COMPREPLY=( $( compgen -W 'follow forget fork' -- $curr ) );;
r*)
COMPREPLY=( $( compgen -W 'rename revert' -- $curr ) );;
s*)
COMPREPLY=( $( compgen -W 'status' -- $curr ) );;
*)
COMPREPLY=( $( compgen -W 'help init status follow forget rename diff commit revert fork apply' -- $curr ) );;
esac
fi
return 0
}
complete -F _UseFragments -o filenames fragments