0
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-09-19 04:01:21 +02:00
ohmyzsh/plugins/jenv/jenv.plugin.zsh
John Burwell e8b9958926 Add jenv plugin
Initializes jenv and provides the jenv_prompt_info funtion to add
Java version information to prompts.  This function is stubbed in
prompt_info_functions script to allow it to be safely called
regardless of whether or not the jenv plugin is loaded.

It also splits detection of the plugin/versions directory and bin directory
to suppport the way Homebrew splits the jenv bin and data directories
2018-08-19 19:12:24 +02:00

33 lines
848 B
Bash

_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
FOUND_JENV=1
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
export JENV_ROOT=$jenvdir
fi
done
unset jenvdir
if [ $FOUND_JENV -eq 0 ] ; then
function jenv_prompt_info() { echo "system: $(java -version 2>&1 | cut -f 2 -d ' ')" }
fi