Skip to content

Instantly share code, notes, and snippets.

@dharFr dharFr/pre-commit
Created Mar 26, 2017

Embed
What would you like to do?
Shellcheck pre-commit hook
#!/bin/sh
#
# This pre-commit hook run `shellcheck` against your code when you go to commit.
# See: http://www.shellcheck.net/
#
# To use this script copy it to .git/hooks/pre-commit and make it executable.
# Work out what to diff against, really HEAD will work for any established repository.
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
# get updated files | only .sh files (+ .bashrc/.zshrc) | shellcheck
git diff-index --cached --name-only $against | grep -e \.bashrc -e \.zshrc -e \.bash_profile -e \\.sh$ | xargs shellcheck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.