From 6f9e8a3b268b8c948927caf822cca7ae558f723b Mon Sep 17 00:00:00 2001 From: Ryan Peach Date: Fri, 27 Mar 2026 14:18:00 -0400 Subject: [PATCH] Cleaner check for precommit installation --- home/.zshrc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/home/.zshrc b/home/.zshrc index f908e51..9cdd02f 100644 --- a/home/.zshrc +++ b/home/.zshrc @@ -269,13 +269,22 @@ if [[ $IS_DOCKER ]]; then trap on_exit SIGHUP EXIT fi +# Function to check if pre-commit hooks are installed +check_pre_commit_hooks_installed() { + if [ -f .git/hooks/pre-commit ] && [ -f .git/hooks/pre-push ]; then + return 0 + else + return 1 + fi +} + # I have a problem with not installing pre-commit on all my repos # So this will force me to -check_pre_commit() { +install_pre_commit_hooks() { # Check for the presence of .pre-commit-config.yaml or .pre-commit-config.yml if [[ -f ".pre-commit-config.yaml" || -f ".pre-commit-config.yml" ]]; then # Check if .pre-commit-installed exists - if [[ ! -f ".pre-commit-installed" ]]; then + if [[ ! check_pre_commit_hooks_installed ]]; then echo "Found pre-commit config file. Running pre-commit install..." pre-commit install # Run the pre-commit install command @@ -292,7 +301,7 @@ check_pre_commit() { } # Add the function to run every time you change directories using chpwd hook -add-zsh-hook chpwd check_pre_commit +add-zsh-hook chpwd install_pre_commit_hooks # Neofetch neofetch