#!/usr/bin/env bash set -euo pipefail DOTFILES="${DOTFILES:-$HOME/.dotfiles}" link_file() { local src="$1" local dst="$2" if [[ ! -e "$src" ]]; then echo "missing source: $src" return 1 fi if [[ -L "$dst" && "$(readlink "$dst")" == "$src" ]]; then echo "ok: $dst -> $src" return 0 fi if [[ -e "$dst" || -L "$dst" ]]; then printf "replace %s? [y/N] " "$dst" read -r answer case "$answer" in y|Y|yes|YES) mv "$dst" "$dst.bak.$(date +%Y%m%d%H%M%S)" ;; *) echo "skip: $dst" return 0 ;; esac fi mkdir -p "$(dirname "$dst")" ln -s "$src" "$dst" echo "linked: $dst -> $src" } link_file "$DOTFILES/bash/bashrc" "$HOME/.bashrc" link_file "$DOTFILES/git/gitconfig" "$HOME/.gitconfig"