bash-completion.py 854 B

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