summaryrefslogtreecommitdiff
path: root/plugins/jenv
diff options
context:
space:
mode:
authorJohn Burwell <meaux@cockamamy.net>2016-04-03 01:08:06 -0400
committerMarc Cornellà <marc.cornella@live.com>2018-08-19 19:12:24 +0200
commite8b9958926c6e41fc681983bf4ec7d96e21e27db (patch)
tree05dc281488ec553a75a04c4ee99d6d7d39acf17b /plugins/jenv
parentff6b4c835be54a9529a88849b83284aee61a7126 (diff)
downloadzsh-e8b9958926c6e41fc681983bf4ec7d96e21e27db.tar.gz
zsh-e8b9958926c6e41fc681983bf4ec7d96e21e27db.tar.bz2
zsh-e8b9958926c6e41fc681983bf4ec7d96e21e27db.zip
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
Diffstat (limited to 'plugins/jenv')
-rw-r--r--plugins/jenv/README.md3
-rw-r--r--plugins/jenv/jenv.plugin.zsh33
2 files changed, 36 insertions, 0 deletions
diff --git a/plugins/jenv/README.md b/plugins/jenv/README.md
new file mode 100644
index 000000000..2f27d6786
--- /dev/null
+++ b/plugins/jenv/README.md
@@ -0,0 +1,3 @@
+# jenv oh-my-zsh plugin
+
+[jenv](http://www.jenv.be/) is a Java version manager similiar to [rbenv](http://rbenv.org/) and [pyenv]|(https://github.com/yyuu/pyenv). This plugin initializes jenv and adds provides the jenv_prompt_info function to add Java version information to prompts.
diff --git a/plugins/jenv/jenv.plugin.zsh b/plugins/jenv/jenv.plugin.zsh
new file mode 100644
index 000000000..f131aa2f9
--- /dev/null
+++ b/plugins/jenv/jenv.plugin.zsh
@@ -0,0 +1,33 @@
+_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