From e8b9958926c6e41fc681983bf4ec7d96e21e27db Mon Sep 17 00:00:00 2001 From: John Burwell Date: Sun, 3 Apr 2016 01:08:06 -0400 Subject: 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 --- plugins/jenv/README.md | 3 +++ plugins/jenv/jenv.plugin.zsh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 plugins/jenv/README.md create mode 100644 plugins/jenv/jenv.plugin.zsh (limited to 'plugins/jenv') 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 -- cgit v1.2.3-70-g09d2 From 3a822bb5fdc30e5b623f409af5c894fe9ad90d15 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 19 Aug 2018 19:32:48 +0200 Subject: jenv: refactor and optimize logic --- plugins/jenv/jenv.plugin.zsh | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'plugins/jenv') diff --git a/plugins/jenv/jenv.plugin.zsh b/plugins/jenv/jenv.plugin.zsh index f131aa2f9..6c52635bb 100644 --- a/plugins/jenv/jenv.plugin.zsh +++ b/plugins/jenv/jenv.plugin.zsh @@ -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") -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 +for jenvdir in $jenvdirs; do + if [[ -d "${jenvdir}/bin" ]]; then FOUND_JENV=1 - export PATH="${jenvdir}/bin:$PATH" - eval "$(jenv init - zsh)" + break + fi +done - function jenv_prompt_info() { - echo "$(jenv version-name)" - } +if [[ $FOUND_JENV -eq 0 ]]; then + if (( $+commands[brew] )) && jenvdir="$(brew --prefix jenv)"; then + FOUND_JENV=1 fi - if [ -d $jenvdir/versions -a $FOUND_JENV -eq 0 ] ; then +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 -done -unset jenvdir - -if [ $FOUND_JENV -eq 0 ] ; then +else function jenv_prompt_info() { echo "system: $(java -version 2>&1 | cut -f 2 -d ' ')" } fi + +unset jenvdir FOUND_JENV -- cgit v1.2.3-70-g09d2 From 873dc9cfb8ddc3c9bb398e9dbb27ebea7f6cab81 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 19 Aug 2018 19:41:49 +0200 Subject: jenv: update README --- plugins/jenv/README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'plugins/jenv') diff --git a/plugins/jenv/README.md b/plugins/jenv/README.md index 2f27d6786..8899d21ae 100644 --- a/plugins/jenv/README.md +++ b/plugins/jenv/README.md @@ -1,3 +1,13 @@ -# jenv oh-my-zsh plugin +# jenv 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. +[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 adds 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) +``` -- cgit v1.2.3-70-g09d2 From 3edd424af2316628c7ab8d86b9b2e0207f48fd6f Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 19 Aug 2018 19:43:35 +0200 Subject: jenv: small fix --- plugins/jenv/jenv.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/jenv') diff --git a/plugins/jenv/jenv.plugin.zsh b/plugins/jenv/jenv.plugin.zsh index 6c52635bb..cead0077b 100644 --- a/plugins/jenv/jenv.plugin.zsh +++ b/plugins/jenv/jenv.plugin.zsh @@ -27,4 +27,4 @@ else function jenv_prompt_info() { echo "system: $(java -version 2>&1 | cut -f 2 -d ' ')" } fi -unset jenvdir FOUND_JENV +unset jenvdir jenvdirs FOUND_JENV -- cgit v1.2.3-70-g09d2 From fceae90219c1c8b422a6d0e220e45ce59b9b737a Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 19 Aug 2018 22:33:44 +0200 Subject: jenv: fix brew directory search `brew --prefix jenv` doesn't ensure jenv is installed so we have to recheck if the bin folder is still there. --- plugins/jenv/jenv.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/jenv') diff --git a/plugins/jenv/jenv.plugin.zsh b/plugins/jenv/jenv.plugin.zsh index cead0077b..14c586be9 100644 --- a/plugins/jenv/jenv.plugin.zsh +++ b/plugins/jenv/jenv.plugin.zsh @@ -10,7 +10,7 @@ done if [[ $FOUND_JENV -eq 0 ]]; then if (( $+commands[brew] )) && jenvdir="$(brew --prefix jenv)"; then - FOUND_JENV=1 + [[ -d "${jenvdir}/bin" ]] && FOUND_JENV=1 fi fi -- cgit v1.2.3-70-g09d2 From 7f96f4476c922b037eb287af2e727e17653db1ef Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 1 Oct 2018 12:14:15 +0200 Subject: jenv: update README --- plugins/jenv/README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'plugins/jenv') diff --git a/plugins/jenv/README.md b/plugins/jenv/README.md index 8899d21ae..c043c626e 100644 --- a/plugins/jenv/README.md +++ b/plugins/jenv/README.md @@ -1,9 +1,9 @@ # 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). +and [pyenv](https://github.com/yyuu/pyenv). -This plugin initializes jenv and adds provides the jenv_prompt_info function to add Java +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: @@ -11,3 +11,17 @@ 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 +``` -- cgit v1.2.3-70-g09d2 From 12c516822c7017355e264540b236405e1ab49a84 Mon Sep 17 00:00:00 2001 From: Jesse Farinacci Date: Tue, 22 Jan 2019 10:09:07 -0500 Subject: add brew install path to search recent `brew install jenv` installs to `/usr/local/bin/jenv`, auto-discover it for recent brew installs to avoid secondary, slower search --- plugins/jenv/jenv.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/jenv') diff --git a/plugins/jenv/jenv.plugin.zsh b/plugins/jenv/jenv.plugin.zsh index 14c586be9..2eda8037b 100644 --- a/plugins/jenv/jenv.plugin.zsh +++ b/plugins/jenv/jenv.plugin.zsh @@ -1,4 +1,4 @@ -jenvdirs=("$HOME/.jenv" "/usr/local/jenv" "/opt/jenv") +jenvdirs=("$HOME/.jenv" "/usr/local" "/usr/local/jenv" "/opt/jenv") FOUND_JENV=0 for jenvdir in $jenvdirs; do -- cgit v1.2.3-70-g09d2