#!/usr/bin/env bash # Checks that all required dev tools are installed and sets up # the git hooks. set -euo pipefail shopt -s inherit_errexit readonly dependencies=( cargo cargo-clippy pre-commit shellcheck ) function main() { status "Checking dependencies..." check_dependencies status "Installing git hooks..." pre-commit install --install-hooks -t pre-commit -t pre-merge-commit \ -t pre-push -t prepare-commit-msg -t commit-msg -t post-commit \ -t post-checkout -t post-merge status "Dev environment is set up!" } function status() { printf "\\n\\n[Status] %s\\n" "$1" } function check_dependencies() { missing=0 set +e for dependency in "${dependencies[@]}"; do if ! type "$dependency" >/dev/null 2>/dev/null; then ((missing++)) echo >&2 "Missing dependency: $dependency" fi done set -e if ((missing)); then exit 1 fi } main