Skip to content

Commit ec7eba1

Browse files
Improve pyang bash completion.
1 parent a699b86 commit ec7eba1

File tree

1 file changed

+56
-13
lines changed
  • tools/bash-completion

1 file changed

+56
-13
lines changed

tools/bash-completion/pyang

+56-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
_pyang()
44
{
5-
local cur prev words plugin pl_opts wind=1
5+
local cur prev words plugin hello pl_opts wind=1
66

77
local formats="hypertree dsdl depend sample-xml-skeleton omni yin
88
tree jstree capability yang xsd uml jtox jsonxsl xmi"
@@ -96,10 +96,56 @@ _pyang()
9696
COMPREPLY=()
9797
_get_comp_words_by_ref cur prev cword words
9898

99+
while [[ $wind -lt $cword ]]; do
100+
case ${words[$wind]} in
101+
-f|--format)
102+
plugin=${words[$wind+1]}
103+
;;
104+
-L|--hello)
105+
hello=yes
106+
;;
107+
esac
108+
((wind++))
109+
done
110+
99111
case $prev in
100112
-o)
101-
_filedir
102-
return 0
113+
case $plugin in
114+
dsdl)
115+
_filedir 'dsdl'
116+
;;
117+
jsonxsl)
118+
_filedir '@(xsl|xslt)'
119+
;;
120+
jstree)
121+
_filedir 'js'
122+
;;
123+
jtox)
124+
_filedir 'jtox'
125+
;;
126+
sample-xml-skeleton|hypertree)
127+
_filedir 'xml'
128+
;;
129+
omni)
130+
_filedir 'graffle'
131+
;;
132+
uml)
133+
_filedir 'uml'
134+
;;
135+
xmi)
136+
_filedir 'xmi'
137+
;;
138+
yang)
139+
_filedir 'yang'
140+
;;
141+
yin)
142+
_filedir 'yin'
143+
;;
144+
*)
145+
_filedir
146+
;;
147+
esac
148+
return 0
103149
;;
104150
-W)
105151
COMPREPLY=($(compgen -W 'error none' -- "$cur"))
@@ -118,19 +164,16 @@ _pyang()
118164
esac
119165

120166
if [[ $cur == -* ]]; then
121-
while [[ $wind -lt $cword ]]; do
122-
if [[ ${words[$wind]} == "-f" || ${words[$wind]} == "--format" ]]
123-
then
124-
plugin=${words[$wind+1]}
125-
pl_opts="opts_${plugin//-/_}"
126-
break
127-
fi
128-
done
167+
pl_opts="opts_${plugin//-/_}"
129168
COMPREPLY=($(compgen -W '$opts_global ${!pl_opts}' -- "$cur"))
130169
return 0
131170
fi
132-
133-
_filedir '@(yang|yin)'
171+
172+
if [[ -z $hello ]]; then
173+
_filedir '@(yang|yin)'
174+
else
175+
_filedir 'xml'
176+
fi
134177
}
135178

136179
have pyang && complete -F _pyang pyang

0 commit comments

Comments
 (0)