dotfiles/bootstrap

33 lines
737 B
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
: "${DOTFILES_PATH:=$HOME/.dotfiles}"
: "${DOTFILES_HOME:=$HOME}"
lnk() {
[[ -e "$2" ]] &&
echo -e "\e[31m[ln] $1 (overwritten)\e[0m" ||
echo -e "\r\e[32m[ln] $2\e[0m"
ln -sf "$1" "$2"
}
dr() {
mkdir -p "$1"
echo -e "\e[34m[mkdir] $1\e[0m"
}
dotify() {
local base_dir="$DOTFILES_PATH/$1"
local target_dir="$2"
find "$base_dir" -type d -print0 | while IFS= read -r -d '' dir; do
dr "$DOTFILES_HOME/$target_dir${dir#"$base_dir"}"
find "$dir" -maxdepth 1 -type f -print0 | while IFS= read -r -d '' file; do
lnk "$file" "$DOTFILES_HOME/$target_dir${file#"$base_dir"}"
done
done
}
# let the lord do the linking
dotify "config" ".config"
dotify "bin" "bin"