summaryrefslogtreecommitdiff
path: root/plugins/jenv
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jenv')
-rw-r--r--plugins/jenv/README.md27
-rw-r--r--plugins/jenv/jenv.plugin.zsh30
2 files changed, 57 insertions, 0 deletions
diff --git a/plugins/jenv/README.md b/plugins/jenv/README.md
new file mode 100644
index 000000000..c043c626e
--- /dev/null
+++ b/plugins/jenv/README.md
@@ -0,0 +1,27 @@
+# jenv plugin
+
+[jenv](https://www.jenv.be/) is a Java version manager similiar to [rbenv](https://github.com/rbenv/rbenv)
+and [pyenv](https://github.com/yyuu/pyenv).
+
+This plugin initializes jenv and provides the `jenv_prompt_info` function to add Java
+version information to prompts.
+
+To use, add `jenv` to your plugins array in your zshrc file:
+
+```zsh
+plugins=(... jenv)
+```
+
+## Theme example
+
+You can modify your `$PROMPT` or `$RPROMPT` variables to run `jenv_prompt_info`.
+
+For example:
+```
+PROMPT="%~$ "
+RPROMPT='$(jenv_prompt_info)'
+```
+changes your prompt to:
+```
+~/java/project$ ▋ oracle64-1.6.0.39
+```
diff --git a/plugins/jenv/jenv.plugin.zsh b/plugins/jenv/jenv.plugin.zsh
new file mode 100644
index 000000000..14c586be9
--- /dev/null
+++ b/plugins/jenv/jenv.plugin.zsh
@@ -0,0 +1,30 @@
+jenvdirs=("$HOME/.jenv" "/usr/local/jenv" "/opt/jenv")
+
+FOUND_JENV=0
+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
+ [[ -d "${jenvdir}/bin" ]] && FOUND_JENV=1
+ fi
+fi
+
+if [[ $FOUND_JENV -eq 1 ]]; then
+ export PATH="${jenvdir}/bin:$PATH"
+ eval "$(jenv init - zsh)"
+
+ function jenv_prompt_info() { jenv version-name 2>/dev/null }
+
+ if [[ -d "${jenvdir}/versions" ]]; then
+ export JENV_ROOT=$jenvdir
+ fi
+else
+ function jenv_prompt_info() { echo "system: $(java -version 2>&1 | cut -f 2 -d ' ')" }
+fi
+
+unset jenvdir jenvdirs FOUND_JENV