Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/anki-code/xontrib-argcomplete

Argcomplete support to tab completion of python and xonsh scripts in xonsh shell.
https://github.com/anki-code/xontrib-argcomplete

argcomplete python shell xonsh xontrib

Last synced: 8 days ago
JSON representation

Argcomplete support to tab completion of python and xonsh scripts in xonsh shell.

Awesome Lists containing this project

README

        


Argcomplete support for python and xonsh scripts in xonsh shell.


If you like the idea click ⭐ on the repo and and tweet.


[Demo]

Screenshot made with xontrib-prompt-bar and Konsole.

## Install
```shell script
xpip install xontrib-argcomplete
echo 'xontrib load argcomplete' >> ~/.xonshrc
# Reload xonsh
```

## Usage

First of all you need to [add the argcomplete support to your script](https://kislyuk.github.io/argcomplete/#synopsis):
* The `PYTHON_ARGCOMPLETE_OK` marker should be found in the first 10 lines of the file ([example](https://github.com/anki-code/xontrib-argcomplete/blob/37e24660351780501eed64a2a77cb2a3309c109c/tests/proto.py#L2)).
* Additional `.completer` was set for `add_argument` ([example](https://github.com/anki-code/xontrib-argcomplete/blob/37e24660351780501eed64a2a77cb2a3309c109c/tests/proto.py#L7)).
* `argcomplete.autocomplete(parser)` added before `parser.parse_args()` ([example](https://github.com/anki-code/xontrib-argcomplete/blob/37e24660351780501eed64a2a77cb2a3309c109c/tests/proto.py#L8)).

Example for [`proto.py`](https://github.com/anki-code/xontrib-argcomplete/blob/master/tests/proto.py) sample:
```xsh
xpip install xontrib-argcomplete
xontrib load argcomplete

cd /tmp && git clone https://github.com/anki-code/xontrib-argcomplete
cd xontrib-argcomplete/tests

python proto.py # Suggestions: --help --proto -h
./proto.py --proto tt # Suggestions: http https
./proto.xsh --proto tt # Suggestions: http https
./proto --proto tt # Suggestions: http https

$PATH.append($PWD)
proto --proto tt # Suggestions: http https
```

The argcomplete xonsh completer will be activated with this cases:
```xsh
python script.py
./script.py
./path/script.py

xonsh script.xsh
./script.xsh
./path/script.xsh

# scripts without extension should have "env python" or "env xonsh" or path to python/xonsh in the shebang
./script
script # script should be found in $PATH
```

## Known issues

Windows is not supported. PRs are welcome!

## Development
* To switch on the debug mode run `$XONTRIB_ARGCOMPLETE_DEBUG = True`.
* [Argcomplete environment variables](https://github.com/kislyuk/argcomplete/issues/319#issuecomment-693295017)
* [Argcomplete documentation](https://kislyuk.github.io/argcomplete/)

## Links
* This package is the part of [ergopack](https://github.com/anki-code/xontrib-ergopack) - the pack of ergonomic xontribs.
* This package was created with [xontrib cookiecutter template](https://github.com/xonsh/xontrib-cookiecutter).