From 675c5584c825f85c72936d6110c74da2df143129 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 12 Dec 2012 00:23:49 -0800 Subject: [PATCH] Intial prototype of auto-switching for chruby (issue #40). --- share/chruby/auto.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 share/chruby/auto.sh diff --git a/share/chruby/auto.sh b/share/chruby/auto.sh new file mode 100644 index 00000000..c1b32403 --- /dev/null +++ b/share/chruby/auto.sh @@ -0,0 +1,17 @@ +function chruby_auto() { + local version_file="$PWD/.ruby-version" + + if [[ -f "$version_file" ]]; then + chruby $(cat "$version_file") + export RUBY_VERSIONED_DIRECTORY="$PWD" + elif [[ "$PWD" != "$RUBY_VERSIONED_DIRECTORY"/* ]]; then + chruby_reset + unset RUBY_VERSIONED_DIRECTORY + fi +} + +if [[ -n "$ZSH_VERSION" ]]; then + chpwd_functions=(${chpwd_functions[@]} "chruby_auto") +else + function cd() { builtin cd "$@" && chruby_auto; } +fi