Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions home/.zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,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

Expand All @@ -288,7 +297,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
Expand Down
Loading