#!/usr/bin/env bash set -Eeufo pipefail trap cleanup SIGINT SIGTERM ERR EXIT usage() { cat <&2 -e "${1-}" } info() { msg "${BLUE}>${NOFORMAT} $*" } warn() { msg "${YELLOW}! $*${NOFORMAT}" } completed() { msg "${GREEN}✓${NOFORMAT} $*" } die() { local msg=$1 local code=${2-1} msg "$msg" exit "$code" } parse_params() { while :; do case "${1-}" in -h | --help) usage ;; -v | --verbose) set -x ;; --no-color) NO_COLOR=1 ;; -?*) die "Unknown option: $1" ;; *) break ;; esac shift done return 0 } has() { type "$1" >/dev/null 2>&1 } # renovate: datasource=github-releases depName=twpayne/chezmoi chezmoi="chezmoi@2.73.0" install() { if ! mise="$(command -v mise)"; then mise="${HOME}/.local/bin/mise" info "Installing mise to '${mise}'" if has "curl"; then mise_install_script="$(curl -fsLS https://mise.run)" elif has "wget"; then mise_install_script="$(wget -qO- https://mise.run)" else die "curl or wget required." fi sh -c "${mise_install_script}" unset mise_install_script fi info "Installing dotfiles..." # run from a checkout: apply it as the source; run via `curl | bash`: clone from GitHub if [[ -f "${BASH_SOURCE[0]-}" ]]; then script_dir="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)" "${mise}" x "${chezmoi}" -- chezmoi init --apply --source="${script_dir}" else "${mise}" x "${chezmoi}" -- chezmoi init --apply h3y6e fi completed "All done." return 0 } parse_params "$@" setup_colors install