aboutsummaryrefslogtreecommitdiff
path: root/devscripts/bash-completion.py
diff options
context:
space:
mode:
authorFilippo Valsorda <filippo.valsorda@gmail.com>2012-12-08 00:37:26 +0100
committerFilippo Valsorda <filippo.valsorda@gmail.com>2012-12-08 00:37:26 +0100
commit4c1d273e88a88f7a7b9e09bb2bbadb161d25b615 (patch)
tree71fc9e864d9f75dfadd8844ba35ae1178a5fd15a /devscripts/bash-completion.py
parenta9d2f7e8945abfb792b76ba551f568d3580c30a6 (diff)
it's curious but bash-completion is with - and not _
Diffstat (limited to 'devscripts/bash-completion.py')
-rw-r--r--devscripts/bash-completion.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/devscripts/bash-completion.py b/devscripts/bash-completion.py
new file mode 100644
index 000000000..880db7886
--- /dev/null
+++ b/devscripts/bash-completion.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+import os
+from os.path import dirname as dirn
+import sys
+
+sys.path.append(dirn(dirn((os.path.abspath(__file__)))))
+import youtube_dl
+
+BASH_COMPLETION_FILE = "youtube-dl.bash-completion"
+BASH_COMPLETION_TEMPLATE = "devscripts/bash-completion.template"
+
+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)