Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 86e83c6

Browse files
committed
Rely on readpath if available
`readpath` is available on macOS, ubuntu, and debian by default. Otherwise, fall back to realink -f (the `-f` option is only available in the GNU implementation).
1 parent 3b28022 commit 86e83c6

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

bin/et

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@ unset CDPATH
1111

1212
# Returns the canonical path for its argument, with any symlinks resolved.
1313
function canonical_path() {
14-
case "$(uname -s)" in
15-
Linux)
16-
readlink -f -- "$1"
17-
;;
18-
Darwin)
19-
realpath -q -- "$1"
20-
;;
21-
*)
22-
echo "The host platform is not supported by this tool"
23-
exit 1
24-
esac
14+
if [[ -x "$(which realpath)" ]]; then
15+
realpath -q -- "$1"
16+
elif [[ -x "$(which readlink)" ]]; then
17+
readlink -f -- "$1"
18+
else
19+
echo "The host platform is not supported by this tool"
20+
exit 1
21+
fi
2522
}
2623

2724
SCRIPT_DIR="$(dirname -- "$(canonical_path "${BASH_SOURCE[0]}")")"

0 commit comments

Comments
 (0)