7878 export VIRTUALENVWRAPPER_PROJECT_FILENAME=" .project"
7979fi
8080
81+ # Let the user tell us they never want to cd to projects
82+ # automatically.
83+ if [ " $VIRTUALENVWRAPPER_WORKON_CD " = " " ]
84+ then
85+ export VIRTUALENVWRAPPER_WORKON_CD=1
86+ fi
87+
8188# Remember where we are running from.
8289if [ -z " $VIRTUALENVWRAPPER_SCRIPT " ]
8390then
@@ -658,10 +665,23 @@ function virtualenvwrapper_workon_help {
658665 echo " "
659666 echo " Show this help message."
660667 echo " "
668+ echo " workon (-c|--cd) envname"
669+ echo " "
670+ echo " After activating the environment, cd to the associated"
671+ echo " project directory if it is set."
672+ echo " "
673+ echo " workon (-n|--no-cd) envname"
674+ echo " "
675+ echo " After activating the environment, do not cd to the"
676+ echo " associated project directory."
677+ echo " "
661678}
662679
663680# :help:workon: list or change working virtualenvs
664681function workon {
682+ typeset -a in_args
683+ typeset -a out_args
684+
665685 in_args=( " $@ " )
666686
667687 if [ -n " $ZSH_VERSION " ]
@@ -672,17 +692,31 @@ function workon {
672692 i=0
673693 tst=" -lt"
674694 fi
695+ typeset cd_after_activate=$VIRTUALENVWRAPPER_WORKON_CD
675696 while [ $i $tst $# ]
676697 do
677698 a=" ${in_args[$i]} "
678699 case " $a " in
679700 -h|--help)
680701 virtualenvwrapper_workon_help;
681702 return 0;;
703+ -n|--no-cd)
704+ cd_after_activate=0;;
705+ -c|--cd)
706+ cd_after_activate=1;;
707+ * )
708+ if [ ${# out_args} -gt 0 ]
709+ then
710+ out_args=( " ${out_args[@]-} " " $a " )
711+ else
712+ out_args=( " $a " )
713+ fi ;;
682714 esac
683715 i=$(( $i + 1 ))
684716 done
685717
718+ set -- " ${out_args[@]} "
719+
686720 typeset env_name=" $1 "
687721 if [ " $env_name " = " " ]
688722 then
@@ -745,7 +779,7 @@ function workon {
745779
746780 }'
747781
748- virtualenvwrapper_run_hook " post_activate"
782+ VIRTUALENVWRAPPER_PROJECT_CD= $cd_after_activate virtualenvwrapper_run_hook " post_activate"
749783
750784 return 0
751785}
0 commit comments