[ie/afreecatv] Support browser impersonation (#10174)
[yt-dlp3.git] / devscripts / zsh-completion.py
blob8e190c00cbcde652c9c591ce66106ff71218de58
1 #!/usr/bin/env python3
3 # Allow direct execution
4 import os
5 import sys
7 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
10 import yt_dlp
12 ZSH_COMPLETION_FILE = 'completions/zsh/_yt-dlp'
13 ZSH_COMPLETION_TEMPLATE = 'devscripts/zsh-completion.in'
16 def build_completion(opt_parser):
17 opts = [opt for group in opt_parser.option_groups
18 for opt in group.option_list]
19 opts_file = [opt for opt in opts if opt.metavar == 'FILE']
20 opts_dir = [opt for opt in opts if opt.metavar == 'DIR']
22 fileopts = []
23 for opt in opts_file:
24 if opt._short_opts:
25 fileopts.extend(opt._short_opts)
26 if opt._long_opts:
27 fileopts.extend(opt._long_opts)
29 diropts = []
30 for opt in opts_dir:
31 if opt._short_opts:
32 diropts.extend(opt._short_opts)
33 if opt._long_opts:
34 diropts.extend(opt._long_opts)
36 flags = [opt.get_opt_string() for opt in opts]
38 with open(ZSH_COMPLETION_TEMPLATE) as f:
39 template = f.read()
41 template = template.replace('{{fileopts}}', '|'.join(fileopts))
42 template = template.replace('{{diropts}}', '|'.join(diropts))
43 template = template.replace('{{flags}}', ' '.join(flags))
45 with open(ZSH_COMPLETION_FILE, 'w') as f:
46 f.write(template)
49 parser = yt_dlp.parseOpts(ignore_config_files=True)[0]
50 build_completion(parser)