1
0
mirror of https://github.com/l1ving/youtube-dl synced 2025-02-09 06:21:43 +08:00
youtube-dl/devscripts/bash-completion.py
Allan Odgaard 7a4e8d91d2 Install bash completion into share/bash-completion/completions
Starting with bash-completion 1.90 (released in November 2011) completion files should be installed in the share/ directory.

They must use the executable’s name for loading on demand, so for this reason, it was necessary to generate the completion file in a new directory, so that it does not clash with the `youtube-dl` executable.

This is because Python’s setup-tools does not support data files to be installed with a different base name.

I have tested this change with both `make install` and `pip install`, as these two install procedures have slightly different code paths.

I removed the `bash-completion` (phony) target from the make file, as we now have a directory with that name, and I could not see the target being referenced anywhere.

Closes #804.
2019-09-10 10:55:06 +02:00

31 lines
869 B
Python
Executable File

#!/usr/bin/env python
from __future__ import unicode_literals
import os
from os.path import dirname as dirn
import sys
sys.path.insert(0, dirn(dirn((os.path.abspath(__file__)))))
import youtube_dl
BASH_COMPLETION_FILE = "bash-completion/youtube-dl"
BASH_COMPLETION_TEMPLATE = "devscripts/bash-completion.in"
def build_completion(opt_parser):
opts_flag = []
for group in opt_parser.option_groups:
for option in group.option_list:
# for every long flag
opts_flag.append(option.get_opt_string())
with open(BASH_COMPLETION_TEMPLATE) as f:
template = f.read()
with open(BASH_COMPLETION_FILE, "w") as f:
# just using the special char
filled_template = template.replace("{{flags}}", " ".join(opts_flag))
f.write(filled_template)
parser = youtube_dl.parseOpts()[0]
build_completion(parser)