]>
Commit | Line | Data |
---|---|---|
cc52de43 | 1 | #!/usr/bin/env python3 |
3b700f8d | 2 | import os |
3b700f8d XC |
3 | import sys |
4 | ||
e5a998f3 | 5 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
6 | ||
7a5c1cfe | 7 | import yt_dlp |
3b700f8d | 8 | |
359d6d86 | 9 | ZSH_COMPLETION_FILE = "completions/zsh/_yt-dlp" |
3b700f8d XC |
10 | ZSH_COMPLETION_TEMPLATE = "devscripts/zsh-completion.in" |
11 | ||
12 | ||
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"] | |
18 | ||
19 | fileopts = [] | |
20 | for opt in opts_file: | |
21 | if opt._short_opts: | |
22 | fileopts.extend(opt._short_opts) | |
23 | if opt._long_opts: | |
24 | fileopts.extend(opt._long_opts) | |
25 | ||
26 | diropts = [] | |
27 | for opt in opts_dir: | |
28 | if opt._short_opts: | |
29 | diropts.extend(opt._short_opts) | |
30 | if opt._long_opts: | |
31 | diropts.extend(opt._long_opts) | |
32 | ||
33 | flags = [opt.get_opt_string() for opt in opts] | |
34 | ||
35 | with open(ZSH_COMPLETION_TEMPLATE) as f: | |
36 | template = f.read() | |
37 | ||
38 | template = template.replace("{{fileopts}}", "|".join(fileopts)) | |
39 | template = template.replace("{{diropts}}", "|".join(diropts)) | |
40 | template = template.replace("{{flags}}", " ".join(flags)) | |
41 | ||
42 | with open(ZSH_COMPLETION_FILE, "w") as f: | |
43 | f.write(template) | |
44 | ||
582be358 | 45 | |
7a5c1cfe | 46 | parser = yt_dlp.parseOpts()[0] |
3b700f8d | 47 | build_completion(parser) |