install.fairie/.local/share/chezmoi/home/dot_local/bin/executable_squash-symlink

18 lines
368 B
Bash

#!/usr/bin/env bash
set -e
for link; do
test -h "$link" || continue
dir=$(dirname "$link")
reltarget=$(readlink "$link")
case $reltarget in
/*) abstarget=$reltarget;;
*) abstarget=$dir/$reltarget;;
esac
rm -fv "$link"
cp -afv "$abstarget" "$link" || {
# Restore link on failure
rm -rfv "$link"
ln -sfv "$reltarget" "$link"
}
done