install: create relative symlinks to dotfiles

This commit is contained in:
Fernando Schauenburg 2021-11-22 08:58:42 +01:00
parent 7b8116185c
commit 25a0fd2437

View file

@ -144,12 +144,12 @@ prune_cmd() {
fi fi
} }
# Make sure $2 is a link to $1. # Make sure $1 is a (relative) symlink to $2.
link() { link() {
target="$(realpath -s "$1")" target="$(python -c "import os; print os.path.relpath('$2','$(dirname $1)')")"
[ "$(readlink "$2")" = "$target" ] && { ok "$2"; return; } [ "$(readlink "$1")" = "$target" ] && { ok "$1 -> $target"; return; }
change "LINK $2 -> $target" change "LINK $1 -> $target"
dry_run || ln -sf "$target" "$2" dry_run || ln -sf "$target" "$1"
} }
# Ensure $1 and $2 contents are equal, updating $1 if needed. # Ensure $1 and $2 contents are equal, updating $1 if needed.
@ -162,10 +162,6 @@ equal_content() {
dry_run || cp -f "$2" "$1" dry_run || cp -f "$2" "$1"
} }
relative_path() {
python -c "import os.path; print os.path.relpath('$1','${2:-$PWD}')"
}
deploy() { deploy() {
find "$1" -type f | while read src; do find "$1" -type f | while read src; do
src_dir="$(dirname "$src")" src_dir="$(dirname "$src")"
@ -175,7 +171,7 @@ deploy() {
filename="$(basename "$src")" filename="$(basename "$src")"
[ "$filename" = '.keep' ] && continue [ "$filename" = '.keep' ] && continue
link "$src" "$dest_dir/$filename" link "$dest_dir/$filename" "$src"
done done
} }