Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canonicalize symlinked paths to rbenv executable #49

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion bin/rbenv-doctor
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down