We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
ZSH completion fails with invalid option definition
I'm using v2.10.2 installed via the [latest Arch package](https://archlinux.org/packages/community/any/visidata/). Visidata shell completion in my ZSH is currently broken.

```
$ vd <tab>
_arguments:comparguments:327: invalid option definition: --fmt_expand_list[format str to use for names of columns expanded from list (colname, index) (default: %s[%s])]:str
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `dev/zsh-completion.py`
Content:
```
1 #!/usr/bin/env python
2 from __future__ import unicode_literals
3 
4 import os
5 from os.path import dirname as dirn
6 import sys
7 import re
8 
9 sys.path.insert(0, dirn(dirn((os.path.abspath(__file__)))))
10 from visidata import vd
11 from visidata.main import option_aliases
12 
13 ZSH_COMPLETION_FILE = "_visidata"
14 ZSH_COMPLETION_TEMPLATE = "dev/zsh-completion.in"
15 pat_class = re.compile("'(.*)'")
16 pat_select = re.compile("^\([^)]*\)")
17 
18 
19 def generate_completion(opt):
20     prefix = "--" + opt.name
21     shortnames = [key for key, value in option_aliases.items() if value[0] == opt.name]
22     if len(shortnames):
23         if len(shortnames[0]) == 1:
24             shortname = "-" + shortnames[0]
25         else:
26             shortname = "--" + shortnames[0]
27         prefix = "{" + f"{shortname},{prefix}" + "}"
28     if isinstance(opt.value, bool):
29         completion = ""
30     else:
31         completion = ":" + pat_class.findall(str(opt.value.__class__))[0]
32     if opt.name in ["play", "output", "visidata_dir", "config"]:
33         completion += ":_files"
34     elif opt.name in ["plugins_url", "motd_url"]:
35         completion += ":_urls"
36     helpstr = opt.helpstr.replace("[", "\\[").replace("]", "\\]")
37     selections = pat_select.findall(helpstr)
38     if len(selections):
39         completion += f":{selections[0].replace('/', ' ')}"
40     # TODO: use `zstyle ':completion:*' extra-verbose true`
41     # to control the display of default value
42     helpstr = helpstr + f" (default: {opt.value})"
43     return f"{prefix}'[{helpstr}]{completion}'"
44 
45 
46 flags = [generate_completion(vd._options[opt]["default"]) for opt in vd._options]
47 
48 with open(ZSH_COMPLETION_TEMPLATE) as f:
49     template = f.read()
50 
51 template = template.replace("{{flags}}", " \\\n    ".join(flags))
52 
53 with open(ZSH_COMPLETION_FILE, "w") as f:
54     f.write(template)
55
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/dev/zsh-completion.py b/dev/zsh-completion.py
--- a/dev/zsh-completion.py
+++ b/dev/zsh-completion.py
@@ -33,13 +33,14 @@
         completion += ":_files"
     elif opt.name in ["plugins_url", "motd_url"]:
         completion += ":_urls"
-    helpstr = opt.helpstr.replace("[", "\\[").replace("]", "\\]")
+    helpstr = opt.helpstr
     selections = pat_select.findall(helpstr)
     if len(selections):
         completion += f":{selections[0].replace('/', ' ')}"
     # TODO: use `zstyle ':completion:*' extra-verbose true`
     # to control the display of default value
     helpstr = helpstr + f" (default: {opt.value})"
+    helpstr = helpstr.replace("[", "\\[").replace("]", "\\]")
     return f"{prefix}'[{helpstr}]{completion}'"

{"golden_diff": "diff --git a/dev/zsh-completion.py b/dev/zsh-completion.py\n--- a/dev/zsh-completion.py\n+++ b/dev/zsh-completion.py\n@@ -33,13 +33,14 @@\n         completion += \":_files\"\n     elif opt.name in [\"plugins_url\", \"motd_url\"]:\n         completion += \":_urls\"\n-    helpstr = opt.helpstr.replace(\"[\", \"\\\\[\").replace(\"]\", \"\\\\]\")\n+    helpstr = opt.helpstr\n     selections = pat_select.findall(helpstr)\n     if len(selections):\n         completion += f\":{selections[0].replace('/', ' ')}\"\n     # TODO: use `zstyle ':completion:*' extra-verbose true`\n     # to control the display of default value\n     helpstr = helpstr + f\" (default: {opt.value})\"\n+    helpstr = helpstr.replace(\"[\", \"\\\\[\").replace(\"]\", \"\\\\]\")\n     return f\"{prefix}'[{helpstr}]{completion}'\"\n", "issue": "ZSH completion fails with invalid option definition\nI'm using v2.10.2 installed via the [latest Arch package](https://archlinux.org/packages/community/any/visidata/). Visidata shell completion in my ZSH is currently broken.\r\n\r\n```\r\n$ vd <tab>\r\n_arguments:comparguments:327: invalid option definition: --fmt_expand_list[format str to use for names of columns expanded from list (colname, index) (default: %s[%s])]:str\r\n```\n", "before_files": [{"content": "#!/usr/bin/env python\nfrom __future__ import unicode_literals\n\nimport os\nfrom os.path import dirname as dirn\nimport sys\nimport re\n\nsys.path.insert(0, dirn(dirn((os.path.abspath(__file__)))))\nfrom visidata import vd\nfrom visidata.main import option_aliases\n\nZSH_COMPLETION_FILE = \"_visidata\"\nZSH_COMPLETION_TEMPLATE = \"dev/zsh-completion.in\"\npat_class = re.compile(\"'(.*)'\")\npat_select = re.compile(\"^\\([^)]*\\)\")\n\n\ndef generate_completion(opt):\n    prefix = \"--\" + opt.name\n    shortnames = [key for key, value in option_aliases.items() if value[0] == opt.name]\n    if len(shortnames):\n        if len(shortnames[0]) == 1:\n            shortname = \"-\" + shortnames[0]\n        else:\n            shortname = \"--\" + shortnames[0]\n        prefix = \"{\" + f\"{shortname},{prefix}\" + \"}\"\n    if isinstance(opt.value, bool):\n        completion = \"\"\n    else:\n        completion = \":\" + pat_class.findall(str(opt.value.__class__))[0]\n    if opt.name in [\"play\", \"output\", \"visidata_dir\", \"config\"]:\n        completion += \":_files\"\n    elif opt.name in [\"plugins_url\", \"motd_url\"]:\n        completion += \":_urls\"\n    helpstr = opt.helpstr.replace(\"[\", \"\\\\[\").replace(\"]\", \"\\\\]\")\n    selections = pat_select.findall(helpstr)\n    if len(selections):\n        completion += f\":{selections[0].replace('/', ' ')}\"\n    # TODO: use `zstyle ':completion:*' extra-verbose true`\n    # to control the display of default value\n    helpstr = helpstr + f\" (default: {opt.value})\"\n    return f\"{prefix}'[{helpstr}]{completion}'\"\n\n\nflags = [generate_completion(vd._options[opt][\"default\"]) for opt in vd._options]\n\nwith open(ZSH_COMPLETION_TEMPLATE) as f:\n    template = f.read()\n\ntemplate = template.replace(\"{{flags}}\", \" \\\\\\n    \".join(flags))\n\nwith open(ZSH_COMPLETION_FILE, \"w\") as f:\n    f.write(template)\n", "path": "dev/zsh-completion.py"}], "after_files": [{"content": "#!/usr/bin/env python\nfrom __future__ import unicode_literals\n\nimport os\nfrom os.path import dirname as dirn\nimport sys\nimport re\n\nsys.path.insert(0, dirn(dirn((os.path.abspath(__file__)))))\nfrom visidata import vd\nfrom visidata.main import option_aliases\n\nZSH_COMPLETION_FILE = \"_visidata\"\nZSH_COMPLETION_TEMPLATE = \"dev/zsh-completion.in\"\npat_class = re.compile(\"'(.*)'\")\npat_select = re.compile(\"^\\([^)]*\\)\")\n\n\ndef generate_completion(opt):\n    prefix = \"--\" + opt.name\n    shortnames = [key for key, value in option_aliases.items() if value[0] == opt.name]\n    if len(shortnames):\n        if len(shortnames[0]) == 1:\n            shortname = \"-\" + shortnames[0]\n        else:\n            shortname = \"--\" + shortnames[0]\n        prefix = \"{\" + f\"{shortname},{prefix}\" + \"}\"\n    if isinstance(opt.value, bool):\n        completion = \"\"\n    else:\n        completion = \":\" + pat_class.findall(str(opt.value.__class__))[0]\n    if opt.name in [\"play\", \"output\", \"visidata_dir\", \"config\"]:\n        completion += \":_files\"\n    elif opt.name in [\"plugins_url\", \"motd_url\"]:\n        completion += \":_urls\"\n    helpstr = opt.helpstr\n    selections = pat_select.findall(helpstr)\n    if len(selections):\n        completion += f\":{selections[0].replace('/', ' ')}\"\n    # TODO: use `zstyle ':completion:*' extra-verbose true`\n    # to control the display of default value\n    helpstr = helpstr + f\" (default: {opt.value})\"\n    helpstr = helpstr.replace(\"[\", \"\\\\[\").replace(\"]\", \"\\\\]\")\n    return f\"{prefix}'[{helpstr}]{completion}'\"\n\n\nflags = [generate_completion(vd._options[opt][\"default\"]) for opt in vd._options]\n\nwith open(ZSH_COMPLETION_TEMPLATE) as f:\n    template = f.read()\n\ntemplate = template.replace(\"{{flags}}\", \" \\\\\\n    \".join(flags))\n\nwith open(ZSH_COMPLETION_FILE, \"w\") as f:\n    f.write(template)\n", "path": "dev/zsh-completion.py"}]}