]> jfr.im git - yt-dlp.git/blame_incremental - devscripts/bash-completion.py
[cleanup] Fix misc bugs (#8968)
[yt-dlp.git] / devscripts / bash-completion.py
... / ...
CommitLineData
1#!/usr/bin/env python3
2
3# Allow direct execution
4import os
5import sys
6
7sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
8
9
10import yt_dlp
11
12BASH_COMPLETION_FILE = "completions/bash/yt-dlp"
13BASH_COMPLETION_TEMPLATE = "devscripts/bash-completion.in"
14
15
16def build_completion(opt_parser):
17 opts_flag = []
18 for group in opt_parser.option_groups:
19 for option in group.option_list:
20 # for every long flag
21 opts_flag.append(option.get_opt_string())
22 with open(BASH_COMPLETION_TEMPLATE) as f:
23 template = f.read()
24 with open(BASH_COMPLETION_FILE, "w") as f:
25 # just using the special char
26 filled_template = template.replace("{{flags}}", " ".join(opts_flag))
27 f.write(filled_template)
28
29
30parser = yt_dlp.parseOpts(ignore_config_files=True)[0]
31build_completion(parser)