Permalink
Browse files

allow cd to fail, make it more shells friendly and error resistant

  • Loading branch information...
1 parent d9375cf commit 53902711212bfa0dbbc26309bd9f95497fed8ea7 @mpapis mpapis committed Feb 12, 2012
Showing with 19 additions and 10 deletions.
  1. +19 −10 activate.sh
View
@@ -1,18 +1,27 @@
#!/usr/bin/env bash
-DIR="$(dirname $0)"
+AUTOENV_DIR="$(dirname $0)"
-function autoenv-init(){
- # Run detect script and split it up.
- saveIFS=$IFS; IFS=$'\n'; cmds=($($DIR/detect_env.py)); IFS=$saveIFS
+autoenv-init()
+{
+ typeset IFS cmd
+ typeset -a cmds
+ IFS=$'\n'
+ cmds=( $( "${AUTOENV_DIR}/detect_env.py" ) )
- for cmd in ${cmds}
- do
- eval $cmd
- done
+ for cmd in ${cmds}
+ do
+ eval $cmd
+ done
}
-function cd(){
- builtin cd "$@"
+cd()
+{
+ if builtin cd "$@"
+ then
autoenv-init
+ return 0
+ else
+ return $?
+ fi
}

0 comments on commit 5390271

Please sign in to comment.