fix and update zsh completion (#4972)
- backslash-escape '[' and ']' - replace single quotes with '\'' instead of " - ignore SUPPRESSed options
This commit is contained in:
@@ -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() + ">'"
|
||||
|
||||
Reference in New Issue
Block a user