Skip to content

Instantly share code, notes, and snippets.

@cboddy
Last active December 3, 2019 00:09
Show Gist options
  • Save cboddy/67fa8a2a4664a3c0faa1097d15d021e2 to your computer and use it in GitHub Desktop.
Save cboddy/67fa8a2a4664a3c0faa1097d15d021e2 to your computer and use it in GitHub Desktop.
pre-commit git hook for python projects to run autopep8 linter
#!/bin/bash
# run autopep8 linter on any python files that are part of the commit
# and modify them in-place to conform to pep8
git diff --cached --name-only | egrep '\.py$' | xargs --no-run-if-empty autopep8 -ri
# re-index files staged for commit
git diff --cached --name-only | egrep '\.py$'| xargs -l git add
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment