Created
March 9, 2021 14:00
-
-
Save mttbernardini/b888a04a78abf11176eedf929dba070a to your computer and use it in GitHub Desktop.
Convert absolute symlinks to relative symlinks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
for f in "$@"; do | |
path=$(readlink "$f") | |
if [ -n "$path" ]; then | |
cd "$(dirname "$f")" | |
rpath=$(realpath -s --relative-to="$PWD" "$path") | |
[ ! $? ] && echo "broken symlink: $f" >&2 | |
cd - > /dev/null | |
if [ -n "$rpath" ] && [ "$path" != "$rpath" ]; then | |
echo "$f: $path -> $rpath" | |
ln -sfT "$rpath" "$f" | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment