add zsh completion script (#150)
This commit is contained in:
9
Makefile
9
Makefile
@@ -24,7 +24,7 @@ test:
|
|||||||
executable:
|
executable:
|
||||||
scripts/pyinstaller.py
|
scripts/pyinstaller.py
|
||||||
|
|
||||||
completion: data/completion/gallery-dl
|
completion: data/completion/gallery-dl data/completion/_gallery-dl
|
||||||
|
|
||||||
man: data/man/gallery-dl.1 data/man/gallery-dl.conf.5
|
man: data/man/gallery-dl.1 data/man/gallery-dl.conf.5
|
||||||
|
|
||||||
@@ -39,5 +39,8 @@ data/man/gallery-dl.1: gallery_dl/option.py gallery_dl/version.py scripts/man.py
|
|||||||
data/man/gallery-dl.conf.5: docs/configuration.rst gallery_dl/version.py scripts/man.py
|
data/man/gallery-dl.conf.5: docs/configuration.rst gallery_dl/version.py scripts/man.py
|
||||||
$(PYTHON) scripts/man.py
|
$(PYTHON) scripts/man.py
|
||||||
|
|
||||||
data/completion/gallery-dl: gallery_dl/option.py scripts/bash_completion.py
|
data/completion/gallery-dl: gallery_dl/option.py scripts/completion_bash.py
|
||||||
$(PYTHON) scripts/bash_completion.py
|
$(PYTHON) scripts/completion_bash.py
|
||||||
|
|
||||||
|
data/completion/_gallery-dl: gallery_dl/option.py scripts/completion_zsh.py
|
||||||
|
$(PYTHON) scripts/completion_zsh.py
|
||||||
|
|||||||
51
scripts/completion_zsh.py
Executable file
51
scripts/completion_zsh.py
Executable file
@@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright 2020 Mike Fährmann
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
|
# published by the Free Software Foundation.
|
||||||
|
|
||||||
|
"""Generate bash completion script from gallery-dl's argument parser"""
|
||||||
|
|
||||||
|
import util
|
||||||
|
from gallery_dl import option
|
||||||
|
|
||||||
|
|
||||||
|
TEMPLATE = """#compdef gallery-dl
|
||||||
|
|
||||||
|
local curcontext="$curcontext"
|
||||||
|
typeset -A opt_args
|
||||||
|
|
||||||
|
local rc=1
|
||||||
|
_arguments -C -S \\
|
||||||
|
%(opts)s \\
|
||||||
|
'*:URL:_urls' && rc=0
|
||||||
|
|
||||||
|
return rc
|
||||||
|
"""
|
||||||
|
|
||||||
|
opts = []
|
||||||
|
for action in option.build_parser()._actions:
|
||||||
|
|
||||||
|
if not action.option_strings:
|
||||||
|
continue
|
||||||
|
elif len(action.option_strings) == 1:
|
||||||
|
opt = action.option_strings[0]
|
||||||
|
else:
|
||||||
|
opt = "{" + ",".join(action.option_strings) + "}"
|
||||||
|
|
||||||
|
opt += "'[" + action.help.replace("'", '"') + "]'"
|
||||||
|
|
||||||
|
if action.metavar:
|
||||||
|
opt += ":'<" + action.metavar.lower() + ">'"
|
||||||
|
if action.metavar in ("FILE", "CFG", "DEST"):
|
||||||
|
opt += ":_files"
|
||||||
|
|
||||||
|
opts.append(opt)
|
||||||
|
|
||||||
|
|
||||||
|
PATH = util.path("data/completion/_gallery-dl")
|
||||||
|
with open(PATH, "w", encoding="utf-8") as file:
|
||||||
|
file.write(TEMPLATE % {"opts": " \\\n".join(opts)})
|
||||||
1
setup.py
1
setup.py
@@ -37,6 +37,7 @@ FILES = [
|
|||||||
(path, [f for f in files if check_file(f)])
|
(path, [f for f in files if check_file(f)])
|
||||||
for (path, files) in [
|
for (path, files) in [
|
||||||
("share/bash-completion/completions", ["data/completion/gallery-dl"]),
|
("share/bash-completion/completions", ["data/completion/gallery-dl"]),
|
||||||
|
("share/zsh/site-functions" , ["data/completion/_gallery-dl"]),
|
||||||
("share/man/man1" , ["data/man/gallery-dl.1"]),
|
("share/man/man1" , ["data/man/gallery-dl.1"]),
|
||||||
("share/man/man5" , ["data/man/gallery-dl.conf.5"]),
|
("share/man/man5" , ["data/man/gallery-dl.conf.5"]),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user