-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompletion.bash
112 lines (101 loc) · 2 KB
/
completion.bash
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
_comp_rtm_pkg_list(){
local pkgnames
COMPREPLY=()
pkgnames="`rtmpack list-names`"
IFS=$'\n'
COMPREPLY=($(compgen -W "${pkgnames}" -- $1))
unset IFS
return 0
}
_comp_rtm_file_list(){
local pkgpath filenames
COMPREPLY=()
pkgpath="`rtmpack find $1`"
filenames=$(for fname in `ls -1 ${pkgpath}/$2 2> /dev/null`; do echo ${fname/\/*\//}; done)
COMPREPLY=($(compgen -W "${filenames}" -- $3))
return 0
}
_comp_rtm_pkg_and_xml_list(){
local pkgnames filenames
COMPREPLY=()
pkgnames="`rtmpack list-names`"
filenames=$(for fname in `ls -1 ./*.xml 2> /dev/null`; do echo ${fname/.\//}; done)
IFS=$'\n'
COMPREPLY=($(compgen -W "${pkgnames}
${filenames}" -- $1))
unset IFS
return 0
}
comp_rtmpack(){
arg=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=()
case ${COMP_CWORD} in
1)
COMPREPLY=($(compgen -W "find depend list-names" -- $arg))
return 0
;;
2)
local prev
prev=${COMP_WORDS[COMP_CWORD-1]}
if [[ "${prev}" != "list-names" ]]; then
_comp_rtm_pkg_list ${arg}
fi
return 0
;;
*)
;;
esac
return 0
}
comp_rtmcd()
{
local arg
arg=${COMP_WORDS[COMP_CWORD]}
_comp_rtm_pkg_list ${arg}
return 0
}
comp_rtmrun()
{
arg=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=()
case ${COMP_CWORD} in
1)
_comp_rtm_pkg_list ${arg}
return 0
;;
2)
local prev
prev=${COMP_WORDS[COMP_CWORD-1]}
_comp_rtm_file_list ${prev} "" ${arg}
return 0
;;
*)
;;
esac
return 0
}
comp_rtmlaunch()
{
arg=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=()
case ${COMP_CWORD} in
1)
_comp_rtm_pkg_and_xml_list $arg
return 0
;;
2)
local prev
prev=${COMP_WORDS[COMP_CWORD-1]}
_comp_rtm_file_list ${prev} "*.xml" ${arg}
return 0
;;
*)
;;
esac
return 0
}
complete -F comp_rtmpack rtmpack
complete -F comp_rtmcd rtmcd
complete -F comp_rtmcd rtmmake
complete -F comp_rtmrun rtmrun
complete -F comp_rtmlaunch rtmlaunch