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)