From 351ddb1095a3b954051560b5378358a3987522d9 Mon Sep 17 00:00:00 2001 From: Sakuragawa Misty Date: Tue, 10 Aug 2021 05:54:51 +0800 Subject: [PATCH] Adapt conda.bash for bash associative array --- pyenv.d/rehash/conda.bash | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/pyenv.d/rehash/conda.bash b/pyenv.d/rehash/conda.bash index 9e477862..bfc88b31 100644 --- a/pyenv.d/rehash/conda.bash +++ b/pyenv.d/rehash/conda.bash @@ -34,14 +34,22 @@ make_shims() { } deregister_conda_shims() { - local shim - local shims=() - for shim in ${registered_shims}; do - if ! conda_shim "${shim}" 1>&2; then - shims[${#shims[*]}]="${shim}" - fi - done - registered_shims=" ${shims[@]} " + if [[ -v registered_shims[@] ]]; then # adapted for Bash 4.x's associative array (#1749) + for shim in ${!registered_shims[*]}; do + if conda_shim "${shim}" 1>&2; then + unset registered_shims[${shim}] + fi + done + else + local shim + local shims=() + for shim in ${registered_shims}; do + if ! conda_shim "${shim}" 1>&2; then + shims[${#shims[*]}]="${shim}" + fi + done + registered_shims=" ${shims[@]} " + fi } if conda_exists; then