jenv: refactor and optimize logic

This commit is contained in:
Marc Cornellà 2018-08-19 19:32:48 +02:00
parent e8b9958926
commit 3a822bb5fd

View file

@ -1,33 +1,30 @@
_homebrew-installed() {
type brew &> /dev/null
}
_jenv-from-homebrew-installed() {
brew --prefix jenv &> /dev/null
}
jenvdirs=("$HOME/.jenv" "/usr/local/jenv" "/opt/jenv") jenvdirs=("$HOME/.jenv" "/usr/local/jenv" "/opt/jenv")
if _homebrew-installed && _jenv-from-homebrew-installed ; then
jenvdirs+=($(brew --prefix jenv) "${jenvdirs[@]}")
fi
FOUND_JENV=0 FOUND_JENV=0
for jenvdir in "${jenvdirs[@]}" ; do for jenvdir in $jenvdirs; do
if [ -d $jenvdir/bin -a $FOUND_JENV -eq 0 ] ; then if [[ -d "${jenvdir}/bin" ]]; then
FOUND_JENV=1 FOUND_JENV=1
export PATH="${jenvdir}/bin:$PATH" break
eval "$(jenv init - zsh)"
function jenv_prompt_info() {
echo "$(jenv version-name)"
}
fi
if [ -d $jenvdir/versions -a $FOUND_JENV -eq 0 ] ; then
export JENV_ROOT=$jenvdir
fi fi
done done
unset jenvdir
if [ $FOUND_JENV -eq 0 ] ; then if [[ $FOUND_JENV -eq 0 ]]; then
if (( $+commands[brew] )) && jenvdir="$(brew --prefix jenv)"; then
FOUND_JENV=1
fi
fi
if [[ $FOUND_JENV -eq 1 ]]; then
export PATH="${jenvdir}/bin:$PATH"
eval "$(jenv init - zsh)"
function jenv_prompt_info() { jenv version-name 2>/dev/null }
if [[ -d "${jenvdir}/versions" ]]; then
export JENV_ROOT=$jenvdir
fi
else
function jenv_prompt_info() { echo "system: $(java -version 2>&1 | cut -f 2 -d ' ')" } function jenv_prompt_info() { echo "system: $(java -version 2>&1 | cut -f 2 -d ' ')" }
fi fi
unset jenvdir FOUND_JENV