mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-19 21:41:07 +01: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")
|
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
|
||||||
|
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"
|
export PATH="${jenvdir}/bin:$PATH"
|
||||||
eval "$(jenv init - zsh)"
|
eval "$(jenv init - zsh)"
|
||||||
|
|
||||||
function jenv_prompt_info() {
|
function jenv_prompt_info() { jenv version-name 2>/dev/null }
|
||||||
echo "$(jenv version-name)"
|
|
||||||
}
|
if [[ -d "${jenvdir}/versions" ]]; then
|
||||||
fi
|
|
||||||
if [ -d $jenvdir/versions -a $FOUND_JENV -eq 0 ] ; then
|
|
||||||
export JENV_ROOT=$jenvdir
|
export JENV_ROOT=$jenvdir
|
||||||
fi
|
fi
|
||||||
done
|
else
|
||||||
unset jenvdir
|
|
||||||
|
|
||||||
if [ $FOUND_JENV -eq 0 ] ; then
|
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue