]>
Raphaƫl G. Git Repositories - youtubedl/blob - devscripts/zsh-completion.py
3 from os
.path
import dirname
as dirn
6 sys
.path
.append(dirn(dirn((os
.path
.abspath(__file__
)))))
9 ZSH_COMPLETION_FILE
= "youtube-dl.zsh"
10 ZSH_COMPLETION_TEMPLATE
= "devscripts/zsh-completion.in"
13 def build_completion(opt_parser
):
14 opts
= [opt
for group
in opt_parser
.option_groups
15 for opt
in group
.option_list
]
16 opts_file
= [opt
for opt
in opts
if opt
.metavar
== "FILE"]
17 opts_dir
= [opt
for opt
in opts
if opt
.metavar
== "DIR"]
22 fileopts
.extend(opt
._short
_opts
)
24 fileopts
.extend(opt
._long
_opts
)
29 diropts
.extend(opt
._short
_opts
)
31 diropts
.extend(opt
._long
_opts
)
33 flags
= [opt
.get_opt_string() for opt
in opts
]
35 with open(ZSH_COMPLETION_TEMPLATE
) as f
:
38 template
= template
.replace("{{fileopts}}", "|".join(fileopts
))
39 template
= template
.replace("{{diropts}}", "|".join(diropts
))
40 template
= template
.replace("{{flags}}", " ".join(flags
))
42 with open(ZSH_COMPLETION_FILE
, "w") as f
:
45 parser
= youtube_dl
.parseOpts()[0]
46 build_completion(parser
)