mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-25 15:20:08 +00:00
jenv: refactor and optimize logic
This commit is contained in:
parent
e8b9958926
commit
3a822bb5fd
1 changed files with 21 additions and 24 deletions
|
@ -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")
|
||||
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
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
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() {
|
||||
echo "$(jenv version-name)"
|
||||
}
|
||||
fi
|
||||
if [ -d $jenvdir/versions -a $FOUND_JENV -eq 0 ] ; then
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue