From 079b19053d1add9b9b5808feded0c9f9b36656d0 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 24 Sep 2017 20:03:01 -0400 Subject: [PATCH] completion Signed-off-by: Kenneth Reitz --- docs/advanced.rst | 6 ++---- pipenv/cli.py | 9 ++++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/advanced.rst b/docs/advanced.rst index 6ebb9f4d..4e18d08d 100644 --- a/docs/advanced.rst +++ b/docs/advanced.rst @@ -682,11 +682,9 @@ production environments for reproducible builds. ☤ Shell Completion ------------------ -Set ``_PIPENV_COMPLETE`` and then source the output of the program. -For example, with ``fish``, put this in your -``~/.config/fish/completions/pipenv.fish``:: +For fish: - eval (env _PIPENV_COMPLETE=source-fish pipenv) + eval (pipenv --completion) Magic shell completions are now enabled! diff --git a/pipenv/cli.py b/pipenv/cli.py index cc1308ce..17f208fb 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -1498,7 +1498,14 @@ def cli( sys.exit() if completion: - os.environ['_PIPENV_COMPLETE'] = 'source-{0}'.format(os.environ['SHELL'].split(os.sep)[-1]) + try: + os.environ['_PIPENV_COMPLETE'] = 'source-{0}'.format(os.environ['SHELL'].split(os.sep)[-1]) + except KeyError: + click.echo( + 'Please ensure that the {0} environment variable ' + 'is set.'.format(crayons.white('SHELL', bold=True)), err=True) + sys.exit(1) + c = delegator.run('pipenv') click.echo(c.out) sys.exit(0)