#!/bin/sh set -o errexit set -o nounset DOTFILES=${DOTFILES:-$HOME/.dotfiles} DOTFILES=$(cd "$DOTFILES" && pwd) # Directories where we want the link the contents. CONTAINERS='.config Pictures' main() { cd "$DOTFILES" walk '' } walk() { for path in "$1".[!.]* "$1"..?* "$1"*; do [ -e "$path" ] || [ -L "$path" ] || continue # unmatched glob case $path in .git|.gitignore|link.sh|README*) continue ;; esac if [ -d "$path" ] && is_container "$path"; then walk "$path/" else link "$path" fi done } is_container() { for c in $CONTAINERS; do case $c in "$1"|"$1"/*) return 0 ;; esac done return 1 } link() { src=$DOTFILES/$1 dest=$HOME/$1 mkdir -p "$(dirname "$dest")" if [ -L "$dest" ]; then rm "$dest" elif [ -e "$dest" ]; then mv "$dest" "$dest.bak.$(date +%Y%m%d%H%M%S)" fi ln -s "$src" "$dest" printf 'linked %s\n' "$1" } main