Update dotfiles/.local/bin/symlink-to-files
This commit is contained in:
parent
237dd663df
commit
539a27d040
1 changed files with 23 additions and 0 deletions
23
dotfiles/.local/bin/symlink-to-files
Normal file
23
dotfiles/.local/bin/symlink-to-files
Normal file
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Example: find . -type l -exec /path/tos/script {} +
|
||||
|
||||
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" || {
|
||||
# on failure, restore the symlink
|
||||
rm -rfv "$link"
|
||||
ln -sfv "$reltarget" "$link"
|
||||
}
|
||||
done
|
Loading…
Reference in a new issue