Created
March 27, 2023 11:58
-
-
Save hellwolf/39feed6c494b4b93ebbd6e52aba2e8df to your computer and use it in GitHub Desktop.
Nix Helpers: trace-symlink & trace-which
This file contains hidden or 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
#!/usr/bin/env sh | |
readlinkWithPrint() { | |
link=$(readlink "$1") | |
p=$link | |
[ -n "${p##/*}" ] && p=$(dirname "$1")/$link | |
echo "$p" | |
[ -h "$p" ] && readlinkWithPrint "$p" | |
} | |
a=$1 | |
[ -e "$a" ] && { | |
echo "$a" | |
# extra print if one of the parent is also a symlink | |
b=$(basename "$a") | |
d=$(dirname "$a") | |
p=$(readlink -f "$d")/$b | |
[ "$a" != "$p" ] && echo "$p" | |
# follows the symlink | |
if [ -L "$p" ];then | |
readlinkWithPrint "$p" | |
fi | |
} |
This file contains hidden or 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
#!/usr/bin/env sh | |
a=$(which "$1") && exec trace-symlink "$a" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usages: