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

Added autocomplete helper, docs and gifs - Issue #10 #11

Merged
merged 2 commits into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions docs/completions.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
.. highlight:: console

================
Shell Completion
================

Pipes includes a helper ``--_completion`` flag which can be
used by terminals to provide autocomplete options.
Below are instructions for setting up autocompletion
for Bash, Zsh, and Fish.

If you have ideas for improving these please share them with use
over at the `Pipes repo <http://www.github.com/gtalarico/pipenv-pipes>`_

.. warning::

Pipes cannot activate an pipenv shell when one is already active,
thefore the autocompletion helper does not run either.
Make sure you are not inside a Pipenv Shell when trying to use
the autocomplete helper.

----------------------------

Fish
----

Add a new file ``pipes.fish`` to your Fish config folder
(eg. ``~/.config/fish/completions/pipes.fish``).

.. code:: console

complete --command pipes --arguments '(pipes --_completion (commandline -cp))' --no-files


.. image:: static/gif-autocomplete-fish.gif


----------------------------

Bash + Zsh
-----------

Original code kindly provided by `jonatasbaldin <https://github.com/jonatasbaldin>`_
`here <https://github.com/gtalarico/pipenv-pipes/issues/10>`_

Add the code below to your `.bashrc`:

.. code:: console

# .bashrc
export BASE_SHELL=$(basename $SHELL)

if [[ "$BASE_SHELL" == "zsh" ]] ; then
autoload bashcompinit && bashcompinit
fi

_pipenv-pipes_completions() {
COMPREPLY=($(compgen -W "$(pipes --_completion)" -- "${COMP_WORDS[1]}"))
}

complete -F _pipenv-pipes_completions pipes

.. image:: static/gif-autocomplete-bash.gif
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Pipenv Pipes Documentation
readme
installation
usage
completions
contributing
history

Expand Down
Binary file added docs/static/gif-autocomplete-bash.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/gif-autocomplete-fish.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions pipenv_pipes/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
help='Unlink Project Directory from this Environment')
@click.option('--verbose', '-v', is_flag=True, help='Verbose')
@click.option('--version', is_flag=True, help='Show Version')
@click.option('--_completion', is_flag=True)
@click.pass_context
def pipes(ctx, envname, list_, setlink, unlink, verbose, version):
def pipes(ctx, envname, list_, setlink, unlink, verbose, version, _completion):
"""

Pipes - PipEnv Environment Switcher
Expand Down Expand Up @@ -70,14 +71,16 @@ def pipes(ctx, envname, list_, setlink, unlink, verbose, version):

if env_vars.HAS_CURSES:
import curses # noqa flake8

ensure_env_vars_are_ok(env_vars)
environments = find_environments(env_vars.PIPENV_HOME)
if not environments:
click.echo(
'No pipenv environments found in {}'.format(env_vars.PIPENV_HOME))
sys.exit(1)

if _completion:
return [click.echo(e.envname) for e in environments]

if verbose:
click.echo('\nPIPENV_HOME: {}\n'.format(env_vars.PIPENV_HOME))

Expand Down
7 changes: 7 additions & 0 deletions tests/integration/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ def test_do_link_no_assoc_env(runner, temp_folder):
assert 'no virtualenv has been created' in result.output.lower()


def test_completions(runner):
result = runner.invoke(
pipes, args=['--_completion'], catch_exceptions=False)
assert result.exit_code == 0
assert 'proj1' in result.output


class TestEnsureVars():
""" Check for errors raised if Certain conditions are not met """

Expand Down