From: Travis Swicegood Date: Mon, 13 Feb 2012 20:26:48 +0000 (-0600) Subject: Add in autoenv from @kennethreitz X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=a639898f1b7f25aefe9c4ffbf2ba071658b2ed39;p=common%2Fbash_it.git Add in autoenv from @kennethreitz --- diff --git a/plugins/available/z_autoenv.plugins.bash b/plugins/available/z_autoenv.plugins.bash new file mode 100644 index 0000000..a145a39 --- /dev/null +++ b/plugins/available/z_autoenv.plugins.bash @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +echo "hi from autoenv" +if [[ -n "${ZSH_VERSION}" ]] +then __array_offset=0 +else __array_offset=1 +fi + +autoenv_init() +{ + typeset target home _file + typeset -a _files + target=$1 + home="$(dirname $HOME)" + + _files=( $( + while [[ "$PWD" != "/" && "$PWD" != "$home" ]] + do + _file="$PWD/.env" + if [[ -e "${_file}" ]] + then echo "${_file}" + fi + builtin cd .. + done + ) ) + + _file=${#_files[@]} + while (( _file > 0 )) + do + source "${_files[_file-__array_offset]}" + : $(( _file -= 1 )) + done +} + +cd() +{ + if builtin cd "$@" + then + echo "running autoenv_init" + autoenv_init + return 0 + else + echo "else?" + return $? + fi +} +echo "cd has been replaced"