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 |
|
Current behavior
The current
check-executables-have-shebangshook inpre_commit_hooks/check_executables_have_shebangs.pyvalidates shebang existence for executables. The hook allows any viable#!/...to pass, i.e. the following are all valid:#!/usr/bin/python#!/bin/bash#!/bin/env python#!/usr/bin/env pythonProposed feature
Implement
--require-envand--fixoptions 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--fixis enabled is re-written accordingly.#!/usr/bin/python#!/usr/bin/env python#!/bin/bash#!/usr/bin/env bash#!/bin/env python#!/usr/bin/env python#!/usr/bin/env python