#!/bin/bash
# Summary: Show the current Python version(s) and its origin
#
# Shows the currently selected Python version(s) and how it was
# selected. To obtain only the version string, use `pyenv
# version-name'.

set -e
[ -n "$PYENV_DEBUG" ] && set -x

exitcode=0
OLDIFS="$IFS"
# VAR=() of unquoted value does glob expansion (against the current dir's contents) after IFS-splitting
# which is undesired
set -f
IFS=: PYENV_VERSION_NAMES=($(pyenv-version-name)) || exitcode=$?
set +f
IFS="$OLDIFS"

for PYENV_VERSION_NAME in "${PYENV_VERSION_NAMES[@]}"; do
  echo "$PYENV_VERSION_NAME (set by $(pyenv-version-origin))"
done

exit $exitcode
