Skip to content

Optionally let the check-executables-have-shebangs hook require /usr/bin/env #1273

Description

@chuckatkins

Current behavior

The current check-executables-have-shebangs hook in pre_commit_hooks/check_executables_have_shebangs.py validates shebang existence for executables. The hook allows any viable #!/... to pass, i.e. the following are all valid:

shebang check
#!/usr/bin/python ✅ Pass
#!/bin/bash ✅ Pass
#!/bin/env python ✅ Pass
#!/usr/bin/env python ✅ Pass

Proposed feature

Implement --require-env and --fix options that will require all shebangs to use #!/usr/bin/env .... The options should be off by default. When enabled, no shebang still fails, but an existing shebang also fails if not invoked via #!/usr/bin/env, and if --fix is enabled is re-written accordingly.

shebang check fix
#!/usr/bin/python ❌ Fail #!/usr/bin/env python
#!/bin/bash ❌ Fail #!/usr/bin/env bash
#!/bin/env python ❌ Fail #!/usr/bin/env python
#!/usr/bin/env python ✅ Pass

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions