e8b9958926c6e41fc681983bf4ec7d96e21e27db

Author
John Burwell <meaux@cockamamy.net>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

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

Diff

This diff is truncated to protect this page.

 1diff --git a/lib/prompt_info_functions.zsh b/lib/prompt_info_functions.zsh
 2index 335c02a3d03867efa8674d778189d82a377896c6..1d5c23e41815f2a51555f6fe84d63202fc5ed6e1 100644
 3--- a/lib/prompt_info_functions.zsh
 4+++ b/lib/prompt_info_functions.zsh
 5@@ -12,7 +12,7 @@
 6 # Real implementations will be used when the respective plugins are loaded
 7 function chruby_prompt_info hg_prompt_info pyenv_prompt_info \
 8   rbenv_prompt_info svn_prompt_info vi_mode_prompt_info \
 9-  virtualenv_prompt_info {
10+  virtualenv_prompt_info jenv_prompt_info {
11   return 1
12 }
13 
14diff --git a/plugins/jenv/README.md b/plugins/jenv/README.md
15new file mode 100644
16index 0000000000000000000000000000000000000000..2f27d67861e40828f6086587788c2be1693ca0d9
17--- /dev/null
18+++ b/plugins/jenv/README.md
19@@ -0,0 +1,3 @@
20+# jenv oh-my-zsh plugin
21+
22diff --git a/plugins/jenv/jenv.plugin.zsh b/plugins/jenv/jenv.plugin.zsh
23new file mode 100644
24index 0000000000000000000000000000000000000000..f131aa2f9aae4a92db3d59283de82f1efe0770e2
25--- /dev/null
26+++ b/plugins/jenv/jenv.plugin.zsh
27@@ -0,0 +1,33 @@
28+_homebrew-installed() {
29+    type brew &> /dev/null
30+}
31+
32+_jenv-from-homebrew-installed() {
33+    brew --prefix jenv &> /dev/null
34+}
35+
36+jenvdirs=("$HOME/.jenv" "/usr/local/jenv" "/opt/jenv")
37+if _homebrew-installed && _jenv-from-homebrew-installed ; then
38+    jenvdirs+=($(brew --prefix jenv) "${jenvdirs[@]}")
39+fi
40+
41+FOUND_JENV=0
42+for jenvdir in "${jenvdirs[@]}" ; do
43+    if [ -d $jenvdir/bin -a $FOUND_JENV -eq 0 ] ; then
44+        FOUND_JENV=1
45+        export PATH="${jenvdir}/bin:$PATH"
46+        eval "$(jenv init - zsh)"
47+
48+        function jenv_prompt_info() {
49+          echo "$(jenv version-name)"
50+        }
51+    fi
52+    if [ -d $jenvdir/versions -a $FOUND_JENV -eq 0 ] ; then
53+        export JENV_ROOT=$jenvdir
54+    fi
55+done
56+unset jenvdir
57+
58+if [ $FOUND_JENV -eq 0 ] ; then
59+    function jenv_prompt_info() { echo "system: $(java -version 2>&1 | cut -f 2 -d ' ')" }
60+fi