Skip to content

Instantly share code, notes, and snippets.

@crowjdh
Created October 21, 2023 02:55
Show Gist options
  • Save crowjdh/6d08062285792532db38dbc31358931d to your computer and use it in GitHub Desktop.
Save crowjdh/6d08062285792532db38dbc31358931d to your computer and use it in GitHub Desktop.
#!/bin/sh
# We don't need extra husky dependency for a simple task
COMMIT_LINT_HOOK_PATH="$PWD/.custom_git_hooks"
COMMIT_LINT_CMT_MSG_HOOK_PATH="$COMMIT_LINT_HOOK_PATH/commit-msg"
ensure_hook_dir() {
if [ ! -d "$COMMIT_LINT_HOOK_PATH" ]; then
mkdir "$COMMIT_LINT_HOOK_PATH"
fi
}
create_commit_msg_hook() {
echo "npx --no -- commitlint --edit \"\$1\"" > "$COMMIT_LINT_CMT_MSG_HOOK_PATH"
chmod u+x "$COMMIT_LINT_CMT_MSG_HOOK_PATH"
}
setup_local_git_hooks_path() {
git config --local core.hooksPath "$COMMIT_LINT_HOOK_PATH"
}
set -e
ensure_hook_dir
create_commit_msg_hook
setup_local_git_hooks_path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment