Skip to content

Instantly share code, notes, and snippets.

@fsgreco
Created March 27, 2023 07:30
Show Gist options
  • Save fsgreco/a05294bfb007ce9877f6fd4d8986a4ec to your computer and use it in GitHub Desktop.
Save fsgreco/a05294bfb007ce9877f6fd4d8986a4ec to your computer and use it in GitHub Desktop.
This script set a new folder to git hooks - if using npm set it as a "prepare" script on package.json, it will trigger automatically when you run your fist `npm install`.
#!/bin/bash
# MIT © Santiago Greco - fsgreco@hey.com
# Set new folder to hooks
# In order to get this script working automatically (it triggers when user runs `npm install`):
# 1. place this script inside .githooks folder
# 2. set a script "prepare" on package.json with the command: .githooks/set-hooks.sh
HASHOOKPATH="$(git config core.hooksPath)"
if [[ -z "$HASHOOKPATH" ]]; then
git config core.hooksPath .githooks;
echo "You are installing packages for the first time, I will set git to use hooks on .githooks folder.";
exit 0;
fi
echo "Your hooks are already configured.";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment