3 # Allow direct execution
7 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
12 BASH_COMPLETION_FILE
= "completions/bash/yt-dlp"
13 BASH_COMPLETION_TEMPLATE
= "devscripts/bash-completion.in"
16 def build_completion(opt_parser
):
18 for group
in opt_parser
.option_groups
:
19 for option
in group
.option_list
:
21 opts_flag
.append(option
.get_opt_string())
22 with
open(BASH_COMPLETION_TEMPLATE
) as f
:
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
)
30 parser
= yt_dlp
.parseOpts(ignore_config_files
=True)[0]
31 build_completion(parser
)