]>
Raphaƫl G. Git Repositories - youtubedl/blob - devscripts/zsh-completion.py
f200f2c80aef4da29999ddba75bc1b17e3048a54
2 from __future__
import unicode_literals
5 from os
.path
import dirname
as dirn
8 sys
.path
.append(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
:
47 parser
= youtube_dl
.parseOpts()[0]
48 build_completion(parser
)