diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2026-10-17 10:40:11 -0700 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2026-10-17 10:40:11 -0700 |
| commit | ea127689e0ae2d39b49004be605e541ff80e2621 (patch) | |
| tree | abbe79e5e37792bd8ebea8f9ac788ff5b8aed704 /link.sh | |
| download | openbsd-dotfiles-ea127689e0ae2d39b49004be605e541ff80e2621.zip | |
Initial Commit
Diffstat (limited to 'link.sh')
| -rwxr-xr-x | link.sh | 56 |
1 files changed, 56 insertions, 0 deletions
@@ -0,0 +1,56 @@ +#!/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' + +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 |