From 2e3ef01abbbb7bae16114c4965935266c3775875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 7 Jan 2025 23:40:54 +0100 Subject: [PATCH] Use readarray in bash v4+ to avoid rbenv init hanging For just a handful of people, rbenv init would hang indefinitely. Turning on debugging output suggested that the `read` expression to split PATH into a bash array was hanging, but I could never reproduce this myself. Instead, this uses bash v4+ `readarray` if it's available, or falls back to bash v3 `read` with the default DELIM being a newline character. This will cause a regression if any PATH entries contain a literal newline character, but hopefully people are not relying on such paths. --- libexec/rbenv-commands | 7 ++++++- libexec/rbenv-help | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libexec/rbenv-commands b/libexec/rbenv-commands index a8c08def..3c570cff 100755 --- a/libexec/rbenv-commands +++ b/libexec/rbenv-commands @@ -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 diff --git a/libexec/rbenv-help b/libexec/rbenv-help index 55ded829..cd30c22a 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -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