]>
Raphaƫl G. Git Repositories - youtubedl/blob - devscripts/zsh-completion.py
2 from __future__
import unicode_literals
5 from os
.path
import dirname
as dirn
8 sys
.path
.insert(0, dirn(dirn((os
.path
.abspath(__file__
)))))
11 ZSH_COMPLETION_FILE
= "youtube-dl.zsh"
12 ZSH_COMPLETION_TEMPLATE
= "devscripts/zsh-completion.in"
15 def build_completion(opt_parser
):
16 opts
= [opt
for group
in opt_parser
.option_groups
17 for opt
in group
.option_list
]
18 opts_file
= [opt
for opt
in opts
if opt
.metavar
== "FILE"]
19 opts_dir
= [opt
for opt
in opts
if opt
.metavar
== "DIR"]
24 fileopts
.extend(opt
._short
_opts
)
26 fileopts
.extend(opt
._long
_opts
)
31 diropts
.extend(opt
._short
_opts
)
33 diropts
.extend(opt
._long
_opts
)
35 flags
= [opt
.get_opt_string() for opt
in opts
]
37 with open(ZSH_COMPLETION_TEMPLATE
) as f
:
40 template
= template
.replace("{{fileopts}}", "|".join(fileopts
))
41 template
= template
.replace("{{diropts}}", "|".join(diropts
))
42 template
= template
.replace("{{flags}}", " ".join(flags
))
44 with open(ZSH_COMPLETION_FILE
, "w") as f
:
48 parser
= youtube_dl
.parseOpts()[0]
49 build_completion(parser
)