aboutsummaryrefslogtreecommitdiffstats
path: root/link.sh
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2026-10-17 10:40:11 -0700
committerEugene Triguba <hello@eugenetriguba.com>2026-10-17 10:40:11 -0700
commitea127689e0ae2d39b49004be605e541ff80e2621 (patch)
treeabbe79e5e37792bd8ebea8f9ac788ff5b8aed704 /link.sh
downloadopenbsd-dotfiles-ea127689e0ae2d39b49004be605e541ff80e2621.zip
Initial Commit
Diffstat (limited to 'link.sh')
-rwxr-xr-xlink.sh56
1 files changed, 56 insertions, 0 deletions
diff --git a/link.sh b/link.sh
new file mode 100755
index 0000000..4f79d03
--- /dev/null
+++ b/link.sh
@@ -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