Repository: pypa/pipenv
Pull request: Add `pipenv scripts` command to list scripts in Pipfile
Enhancement discussed in #3686 

Problem statement:
Command to list [scripts] entries
### Is your feature request related to a problem? Please describe.

I sometimes would start typing `pipenv run` and cannot recall what the command I want is named (`release`? `push`? ehh…), and have to ^U and `cat <path to Pipfile>` and look for the `[scripts]` section. It’d be very helpful if I could quickly do this inside my terminal.

### Describe the solution you'd like

Something like

```console
$ pipenv list-scripts
release     python release
test        pytest
format      black src tests
```

Hints from issue discussion:
`list-scripts` is a bit verbose, my first instinct was `pipenv scripts` -- thoughts? Either way it seems odd to add a full command for just this -- would we want other functionality with it?

Invoke uses `--list` as well, we can consider `pipenv run --list` as an option (but I don't particularly like it)
I don’t really have any preferences, all of the mentioned options would work fine for me.
I think this should be rolled into the `pipenv run` command when no command is provided.
When I run `npm run` with no arguments I get:
```
Lifecycle scripts included in example-project:
  start
    npm run develop
  test
    echo "Write tests! -> https://gatsby.dev/unit-testing"

available via `npm run-script`:
  build
    gatsby build
  clean
    gatsby clean
  develop
    gatsby develop
```
I assume this would no longer need a PEEP

As an additional point I think `pipenv run script_command` should print out the command it is running. npm does this and it is useful, especially when passing additional parameters
A quick hack to accomplish this:

Install pipenv as a dev requirement:

>pipenv install -d pipenv

Add a `script` to your Pipfile:

```
[scripts]
list = "./pipenv_list_scripts.py"
```

Add `pipenv_list_scripts.py`:

```
#!/usr/bin/env python
"""
Utility to allow pipenv command listing `scripts` from Pipfile
"""
try:
    import pipenv.core
except ModuleNotFoundError:
    print("This script is only for use in a development environment")
    exit(1)


def main():
    proj = pipenv.core.project
    if not proj:
        print("project not found")
        exit(1)
    scripts = proj.parsed_pipfile.get('scripts', [])
    print("command\tscript")
    for k, v in scripts.items():
        print(f"{k}\t{v}")
    return


if __name__ == '__main__':
    main()
```


@GlenRSmith Rewrite that to be invoked as `pipenv script` and submit a PR, and I’ll approve it 🙂 
@uranusjr Thanks, done. LMK if you have any feedback.

Commit message: Merge pull request #3 from GlenRSmith/dev_test_output

add inspection for 'which python'

Patch to review:
diff --git a/pipenv/cli/command.py b/pipenv/cli/command.py
index 6b9c339226..ec39bcd4bf 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\tscripts\n"
+    for k, v in scripts.items():
+        rpt += u"{0}\t{1}".format(k, v)
+    echo(rpt)
+    return
+
+
 if __name__ == "__main__":
     cli()
diff --git a/tests/integration/test_cli.py b/tests/integration/test_cli.py
index 711f8daa78..f87a3723e8 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:


Code review comments:
diff_hunk: @@ -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\tscripts\n"
+    for k, v in scripts.items():
+        rpt += u"{0}\t{1}".format(k, v)
+    echo(rpt)
+    return
path: pipenv/cli/command.py
text: @user1:
This return has no function.

@author:
Fixed.