Commit 3a822bb5 authored by Marc Cornellà's avatar Marc Cornellà
Browse files

jenv: refactor and optimize logic

parent e8b99589
_homebrew-installed() {
type brew &> /dev/null
}
_jenv-from-homebrew-installed() {
brew --prefix jenv &> /dev/null
}
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
for jenvdir in "${jenvdirs[@]}" ; do
if [ -d $jenvdir/bin -a $FOUND_JENV -eq 0 ] ; then
for jenvdir in $jenvdirs; do
if [[ -d "${jenvdir}/bin" ]]; then
FOUND_JENV=1
export PATH="${jenvdir}/bin:$PATH"
eval "$(jenv init - zsh)"
break
fi
done
function jenv_prompt_info() {
echo "$(jenv version-name)"
}
if [[ $FOUND_JENV -eq 0 ]]; then
if (( $+commands[brew] )) && jenvdir="$(brew --prefix jenv)"; then
FOUND_JENV=1
fi
if [ -d $jenvdir/versions -a $FOUND_JENV -eq 0 ] ; then
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
done
unset jenvdir
if [ $FOUND_JENV -eq 0 ] ; then
else
function jenv_prompt_info() { echo "system: $(java -version 2>&1 | cut -f 2 -d ' ')" }
fi
unset jenvdir FOUND_JENV
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment