Adding support of kislyuk/argcomplete to xonsh.
Project description
Adding support of kislyuk/argcomplete to xonsh.
If you like the idea of xontrib-argcomplete click ⭐ on the repo and stay tuned by watching releases.
Install
xpip install -U xontrib-argcomplete
echo 'xontrib load argcomplete' >> ~/.xonshrc
# Reload xonsh
Usage
Current version of completion is working only for commands that starts with:
python <path/to/python_script.py> ...
<path/to/python_script.py> ...
For example create proto.py
with the content:
#!/usr/bin/env python
# PYTHON_ARGCOMPLETE_OK
import argparse, argcomplete
from argcomplete.completers import ChoicesCompleter
parser = argparse.ArgumentParser()
parser.add_argument("--proto").completer=ChoicesCompleter(('http', 'https', 'ssh', 'rsync', 'wss'))
argcomplete.autocomplete(parser)
args = parser.parse_args()
print('ok')
Then try completion:
python proto.py <Tab>
# Suggestions: --help --proto -h
chmod +x proto.py
./proto.py --proto tt<Tab>
# Suggestions: http https
Known issues
This is the alpha version of the xontrib-argcomplete and the proof of concept. It was tested on Ubuntu+Conda+Xonsh and on Mac.
No completions or "Completions not found" message
To get completions list for your Python script it runs in subprocess shell (sh
by default) with appropriate argcomplete environment variables. The common reason you can get empty list or "Completions not found" message" is that you have different setting for Python in xonsh and in sh
shell.
To test that your script.py
with argparse
and argcomplete
is working properly in sh
try to run:
sh -c 'python script.py'
# OR
sh -c 'python script.py --help' # to avoid full running the script
# AND check the Python version and paths
sh -c 'python -V'
sh -c 'python -c "import sys; print(sys.path)"'
If you see the errors this is the cause why xontrib returns no completions. The causes may be different: xontrib-argcomplete may not properly set the environment and PR to fix is required or your environment is complex and you should synchronize xonsh and sh
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for xontrib-argcomplete-0.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0140dccea2e78715c9b848d459f11b91b466da925f5ea79336faa54bb8acf6c |
|
MD5 | 54774a6db535063e10a2e687a27cc2f1 |
|
BLAKE2b-256 | acdc7a63833341c25d42e19acd6d5f273f505c45f445aaea33fa2ee355a73c08 |
Hashes for xontrib_argcomplete-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a43394950d7f57cdb31afd862aa433526c03b86bd9b4cd7f8100780b7f271b6 |
|
MD5 | af32227176ae7b672a19ab5d498abcaa |
|
BLAKE2b-256 | cba269c8ab841bfa53d297a4b1c21332c53400a69a2a81aad9cfbdd31928d635 |