This repository was archived by the owner on Feb 25, 2025. It is now read-only.
File tree 1 file changed +12
-18
lines changed 1 file changed +12
-18
lines changed Original file line number Diff line number Diff line change 9
9
# Needed because if it is set, cd may print the path it changed to.
10
10
unset CDPATH
11
11
12
- # On Mac OS, readlink -f doesn't work, so follow_links traverses the path one
13
- # link at a time, and then cds into the link destination and find out where it
14
- # ends up.
15
- #
16
- # The function is enclosed in a subshell to avoid changing the working directory
17
- # of the caller.
18
- function follow_links() (
19
- cd -P " $( dirname -- " $1 " ) "
20
- file=" $PWD /$( basename -- " $1 " ) "
21
- while [[ -h " $file " ]]; do
22
- cd -P " $( dirname -- " $file " ) "
23
- file=" $( readlink -- " $file " ) "
24
- cd -P " $( dirname -- " $file " ) "
25
- file=" $PWD /$( basename -- " $file " ) "
26
- done
27
- echo " $file "
28
- )
12
+ # Returns the canonical path for its argument, with any symlinks resolved.
13
+ function canonical_path() {
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
22
+ }
29
23
30
- SCRIPT_DIR=" $( dirname -- " $( follow_links " ${BASH_SOURCE[0]} " ) " ) "
24
+ SCRIPT_DIR=" $( dirname -- " $( canonical_path " ${BASH_SOURCE[0]} " ) " ) "
31
25
ENGINE_DIR=" $( cd " $SCRIPT_DIR /.." ; pwd -P) "
32
26
33
27
case " $( uname -s) " in
You can’t perform that action at this time.
0 commit comments