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