From 86416c5fd62eaa6fd03de0bc1a6f6801f89a37f2 Mon Sep 17 00:00:00 2001 From: John Bates Date: Tue, 19 Sep 2023 12:11:56 -0700 Subject: [PATCH] Canonicalize symlinked paths to rbenv executable --- bin/rbenv-doctor | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/bin/rbenv-doctor b/bin/rbenv-doctor index 50c8576..2d11f49 100755 --- a/bin/rbenv-doctor +++ b/bin/rbenv-doctor @@ -24,6 +24,21 @@ fix-usr-bin() { sed 's:^/usr/bin/:/bin/:' } +# NOTE: readlink -f is supported on MacOS 12.3+ +# (https://apple.stackexchange.com/a/464138/141312) +canonicalize-symlinks() { + files=() + IFS=$'\n' read -d '' -r -a files + count=${#files[@]} + idx=0 + while [[ $idx -lt $count ]]; do + if ! readlink -f "${files[$idx]}" 2> /dev/null; then + echo "${files[$idx]}" + fi + idx=$((idx+1)) + done +} + printc() { local color_name="color_$1" local msg="$2" @@ -55,7 +70,7 @@ fi warnings=0 echo -n "Checking for \`rbenv' in PATH: " -num_locations="$(command-list rbenv | fix-usr-bin | uniq | count-lines)" +num_locations="$(command-list rbenv | fix-usr-bin | canonicalize-symlinks | uniq | count-lines)" if [ "$num_locations" -eq 0 ]; then printc red "not found" echo