Merge pull request #1604 from rbenv/readarray

Use readarray in bash v4+ to avoid rbenv init hanging
This commit is contained in:
Mislav Marohnić 2025-01-07 23:52:57 +01:00 committed by GitHub
commit 1d08efe089
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View File

@ -26,7 +26,12 @@ elif [ "$1" = "--no-sh" ]; then
shift
fi
IFS=: read -d '' -r -a paths <<<"$PATH" || true
if [ "$(type -t readarray)" = "builtin" ]; then
readarray -d : -t paths < <(printf "%s" "$PATH")
else
# bash 3.x compatibility
IFS=: read -r -a paths <<<"$PATH" || true
fi
shopt -s nullglob

View File

@ -154,7 +154,12 @@ print_usage() {
if [ "$1" = "--complete-commands" ]; then
command_prefix="${2:-}"
seen=()
IFS=: read -d '' -r -a paths <<<"$PATH" || true
if [ "$(type -t readarray)" = "builtin" ]; then
readarray -d : -t paths < <(printf "%s" "$PATH")
else
# bash 3.x compatibility
IFS=: read -r -a paths <<<"$PATH" || true
fi
shopt -s nullglob
for path in "${paths[@]}"; do
for command in "${path}/rbenv-${command_prefix}"*; do