refactor: use regex matching instead of for loop

Instead of creating a for-loop where we go through each argument, to
check if current argument is -m and next argument is pip, we instead do
simple regex matching where we look for ` -m pip ` somewhere in the
command which is to be executed.
This commit is contained in:
Christian Fredrik Johnsen 2024-12-27 21:19:59 +01:00
parent 372ffab430
commit b154f3a7d8

View File

@ -6,13 +6,10 @@ if [[ $PYENV_REHASH_COMMAND =~ ^(pip|easy_install)[23](\.\d)?$ ]]; then
PYENV_REHASH_COMMAND="${BASH_REMATCH[1]}" PYENV_REHASH_COMMAND="${BASH_REMATCH[1]}"
fi fi
for (( i=1; i<$#; i++ )); do # Check for ` -m pip ` in arguments
next=$((i+1)) if [[ "$*" =~ [[:space:]]-m[[:space:]]pip[[:space:]] ]]; then
if [[ ${!i} == "-m" && ${!next} == "pip" ]]; then
PYENV_REHASH_COMMAND="pip" PYENV_REHASH_COMMAND="pip"
break fi
fi
done
if [ -x "${PYENV_PIP_REHASH_ROOT}/${PYENV_REHASH_COMMAND}" ]; then if [ -x "${PYENV_PIP_REHASH_ROOT}/${PYENV_REHASH_COMMAND}" ]; then
PYENV_COMMAND_PATH="${PYENV_PIP_REHASH_ROOT}/${PYENV_REHASH_COMMAND##*/}" PYENV_COMMAND_PATH="${PYENV_PIP_REHASH_ROOT}/${PYENV_REHASH_COMMAND##*/}"