Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

~/ completes to \~/ on zsh #503

Open
FlorianPommerening opened this issue Sep 12, 2024 · 0 comments
Open

~/ completes to \~/ on zsh #503

FlorianPommerening opened this issue Sep 12, 2024 · 0 comments

Comments

@FlorianPommerening
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant