fix and update zsh completion (#4972)

- backslash-escape '[' and ']'
- replace single quotes with '\'' instead of "
- ignore SUPPRESSed options
pull/4962/head
Mike Fährmann 9 months ago
parent 77d46e6f0c
commit a50c1472b1
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -10,32 +10,39 @@
"""Generate zsh completion script from gallery-dl's argument parser"""
import util
import argparse
from gallery_dl import option
TEMPLATE = """#compdef gallery-dl
local curcontext="$curcontext"
typeset -A opt_args
local rc=1
_arguments -C -S \\
_arguments -s -S \\
%(opts)s && rc=0
return rc
"""
TR = str.maketrans({
"'": "'\\''",
"[": "\\[",
"]": "\\]",
})
opts = []
for action in option.build_parser()._actions:
if not action.option_strings:
if not action.option_strings or action.help == argparse.SUPPRESS:
continue
elif len(action.option_strings) == 1:
opt = action.option_strings[0]
else:
opt = "{" + ",".join(action.option_strings) + "}"
opt += "'[" + action.help.replace("'", '"') + "]'"
opt += "'[" + action.help.translate(TR) + "]'"
if action.metavar:
opt += ":'<" + action.metavar.lower() + ">'"

Loading…
Cancel
Save