argcomplete
argcomplete copied to clipboard
~/ completes to \~/ on zsh
The alias ~
for the home directory is escaped on zsh.
To reproduce
Test environment:
- Ubuntu 24.04
- Python 3.12.3
- argcomplete 3.1.4-1ubuntu0.1 (this is 3.1.4 with a patch back-ported from 3.3.0 to make it compatible with Python 12.3)
- zsh 5.9
Content of foo.py
#! /usr/bin/env python3
# PYTHON_ARGCOMPLETE_OK
import argcomplete, argparse
parser = argparse.ArgumentParser()
arg = parser.add_argument("file")
arg.completer = argcomplete.completers.FilesCompleter()
argcomplete.autocomplete(parser)
./foo.py ~/.bashr<TAB>
Expected completion is ./foo.py ~/.bashrc
and this is what happens on bash. However on zsh, I get ./foo.py \~/.bashrc
.
In both cases, the FilesCompleter
returns the path as ~/.bashrc
(not escaped), so the escaping happens later on in the pipeline. In particular, this is part of the zsh built-in _describe
which in turn calls compadd
to add the string ~/.bashrc
to the list of suggestions. At this point the string is escaped. There are options to prevent this escaping that can also be passed to _describe
but it is not clear to me, which one to use (https://zsh.sourceforge.io/Doc/zsh_us.pdf, chapter 19.3 for compadd
and 20.6 for _describe
). For example, -Q
would disable escaping completely but this would be an issue for paths with spaces. Then something like -f -W \~
might work but it assumes that the returned values are paths.