1
0
mirror of https://github.com/pyenv/pyenv.git synced 2025-11-08 11:33:49 -05:00

Compare commits

...

3 Commits

Author SHA1 Message Date
Mislav Marohnić
10e96bfc47 rbenv 1.3.2 2025-01-08 15:05:27 +01:00
Mislav Marohnić
896e76c3d5 Merge pull request #1606 from rbenv/no-readarray
Fix traversing PATH for bash < 4.4
2025-01-08 14:48:03 +01:00
Mislav Marohnić
228fbf4c4f Fix traversing PATH for bash < 4.4
Bash versions before 4.4 did not support the `-d` nor `-t` flags for readarray:
https://lists.gnu.org/archive/html/info-gnu/2016-09/msg00012.html

This switches away from readarray/"read" completely in favor of traversing PATH
by using string substitution.
2025-01-08 14:29:19 +01:00
4 changed files with 42 additions and 44 deletions

View File

@@ -12,7 +12,7 @@
set -e
[ -n "$RBENV_DEBUG" ] && set -x
version="1.3.1"
version="1.3.2"
git_revision=""
if cd "${BASH_SOURCE%/*}" 2>/dev/null && git remote -v 2>/dev/null | grep -q rbenv; then

View File

@@ -18,37 +18,33 @@ if [ "$1" = "--complete" ]; then
exit
fi
exclude_shell=
command_prefix="rbenv-"
if [ "$1" = "--sh" ]; then
sh=1
command_prefix="rbenv-sh-"
shift
elif [ "$1" = "--no-sh" ]; then
nosh=1
exclude_shell=1
shift
fi
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-"*; do
command="${command##*rbenv-}"
if [ -n "$sh" ]; then
if [ "${command:0:3}" = "sh-" ]; then
echo "${command##sh-}"
fi
elif [ -n "$nosh" ]; then
if [ "${command:0:3}" != "sh-" ]; then
echo "${command##sh-}"
fi
else
echo "${command##sh-}"
{
PATH_remain="$PATH"
# traverse PATH to find "rbenv-" prefixed commands
while true; do
path="${PATH_remain%%:*}"
if [ -n "$path" ]; then
for rbenv_command in "${path}/${command_prefix}"*; do
rbenv_command="${rbenv_command##*rbenv-}"
if [[ -z $exclude_shell || $rbenv_command != sh-* ]]; then
echo "${rbenv_command##sh-}"
fi
done
fi
[[ $PATH_remain == *:* ]] || break
PATH_remain="${PATH_remain#*:}"
done
} | sort | uniq

View File

@@ -154,25 +154,27 @@ print_usage() {
if [ "$1" = "--complete-commands" ]; then
command_prefix="${2:-}"
seen=()
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
command_name="${command##*/}"
PATH_remain="$PATH"
# traverse PATH to find "rbenv-" prefixed commands
while true; do
path="${PATH_remain%%:*}"
if [ -n "$path" ]; then
for rbenv_command in "${path}/rbenv-"*; do
command_name="${rbenv_command##*/}"
command_name="${command_name#rbenv-}"
command_name="${command_name#sh-}"
[[ $command_name == "${command_prefix}"* ]] || continue
[[ " ${seen[*]} " != *" ${command_name} "* ]] || continue
seen+=("$command_name")
summary=""
eval "$(extract_initial_comment_block < "$command" | collect_documentation)"
eval "$(extract_initial_comment_block < "$rbenv_command" | collect_documentation)"
[ -n "$summary" ] || continue
printf "%s:%s\n" "$command_name" "$summary"
done
fi
[[ $PATH_remain == *:* ]] || break
PATH_remain="${PATH_remain#*:}"
done
exit 0
fi

View File

@@ -4,10 +4,10 @@
.\" Generator: Asciidoctor 2.0.20
.\" Date: 2023-11-08
.\" Manual: Rbenv Manual
.\" Source: rbenv 1.3.1
.\" Source: rbenv 1.3.2
.\" Language: English
.\"
.TH "RBENV" "1" "2023-11-08" "rbenv 1.3.1" "Rbenv Manual"
.TH "RBENV" "1" "2023-11-08" "rbenv 1.3.2" "Rbenv Manual"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0