From de456f23b76363a2a2a972d2d158e750a120d480 Mon Sep 17 00:00:00 2001 From: "Zak B. Elep" Date: Mon, 11 Apr 2016 09:14:42 +0800 Subject: [PATCH] Add plenv plugin Based mostly from pyenv plugin. --- plugins/plenv/plenv.plugin.zsh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 plugins/plenv/plenv.plugin.zsh diff --git a/plugins/plenv/plenv.plugin.zsh b/plugins/plenv/plenv.plugin.zsh new file mode 100644 index 00000000..ec759270 --- /dev/null +++ b/plugins/plenv/plenv.plugin.zsh @@ -0,0 +1,31 @@ +_homebrew-installed() { + type brew &> /dev/null +} + +_plenv-from-homebrew-installed() { + brew --prefix plenv &> /dev/null +} + +FOUND_PLENV=0 +plenvdirs=("$HOME/.plenv" "/usr/local/plenv" "/opt/plenv") +if _homebrew-installed && _plenv-from-homebrew-installed ; then + plenvdirs=($(brew --prefix plenv) "${plenvdirs[@]}") +fi + +for plenvdir in "${plenvdirs[@]}" ; do + if [ -d $plenvdir/bin -a $FOUND_PLENV -eq 0 ] ; then + FOUND_PLENV=1 + export PLENV_ROOT=$plenvdir + export PATH=${plenvdir}/bin:$PATH + eval "$(plenv init - zsh)" + + function plenv_prompt_info() { + echo "$(plenv version-name)" + } + fi +done +unset plenvdir + +if [ $FOUND_PLENV -eq 0 ] ; then + function plenv_prompt_info() { echo "system: $(perl -Mversion -e 'print version->parse($])->normal' 2>&1 )" } +fi