diff --git a/README.md b/README.md index 9b7ff6d0..ef08a525 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,8 @@ Fish is the best shell. You should use it. lock Generates Pipfile.lock. open View a given module in your editor. run Spawns a command installed into the virtualenv. + scripts Displays the shortcuts in the (optional) [scripts] section of + Pipfile. shell Spawns a shell within the virtualenv. sync Installs all packages specified in Pipfile.lock. uninstall Un-installs a provided package and removes it from Pipfile. diff --git a/docs/advanced.rst b/docs/advanced.rst index b2944da9..d8aff57a 100644 --- a/docs/advanced.rst +++ b/docs/advanced.rst @@ -428,6 +428,15 @@ For example: $ pipenv run echospam "indeed" I am really a very silly example indeed +You can then display the names and commands of your shortcuts by running ``pipenv scripts`` in your terminal. + +:: + + $ pipenv scripts + command script + echospam echo I am really a very silly example + + ☤ Support for Environment Variables ----------------------------------- diff --git a/news/3686.feature.rst b/news/3686.feature.rst new file mode 100644 index 00000000..101e369b --- /dev/null +++ b/news/3686.feature.rst @@ -0,0 +1,2 @@ +Add a new command ``pipenv scripts`` to display shortcuts from Pipfile. + diff --git a/pipenv/cli/command.py b/pipenv/cli/command.py index 6b9c3392..4864e6de 100644 --- a/pipenv/cli/command.py +++ b/pipenv/cli/command.py @@ -716,5 +716,26 @@ def clean(ctx, state, dry_run=False, bare=False, user=False): system=state.system) +@cli.command( + short_help="Lists scripts in current environment config.", + context_settings=subcommand_context_no_interspersion, +) +@common_options +@argument("args", nargs=-1) +@pass_state +def scripts(state, args): + """Lists scripts in current environment config.""" + from ..core import project + if not project: + echo(u"project not found", err=True) + exit(1) + scripts = project.parsed_pipfile.get('scripts', {}) + rpt = u"command\tscript\n" + for k, v in scripts.items(): + rpt += u"{0}\t{1}".format(k, v) + echo(rpt) + return 0 + + if __name__ == "__main__": cli() diff --git a/tests/integration/test_cli.py b/tests/integration/test_cli.py index 711f8daa..f87a3723 100644 --- a/tests/integration/test_cli.py +++ b/tests/integration/test_cli.py @@ -197,6 +197,20 @@ def test_bare_output(PipenvInstance): assert p.pipenv('').out +@pytest.mark.cli +def test_scripts(PipenvInstance): + with PipenvInstance() as p: + with open(p.pipfile_path, "w") as f: + contents = """ +[scripts] +pyver = "which python" + """.strip() + f.write(contents) + c = p.pipenv('scripts') + assert 'pyver' in c.out + assert 'which python' in c.out + + @pytest.mark.cli def test_help(PipenvInstance): with PipenvInstance() as p: