diff .bashrc @ 531:42d3418e9154

.bashrc bin/setup-X.sh
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 25 Sep 2013 11:54:06 -0700
parents b2ca27f83d5f
children e1aa8835edb7
line wrap: on
line diff
--- a/.bashrc	Tue Sep 24 21:22:26 2013 -0700
+++ b/.bashrc	Wed Sep 25 11:54:06 2013 -0700
@@ -356,6 +356,39 @@
     done
 }
 
+nearest-venv() {
+if [[ "$#" == "0" ]]
+then
+directory=$PWD
+else
+directory=$1
+fi
+directory=$(python -c "import os; print os.path.abspath('${directory}')")
+
+while [[ "${directory}" != "/" ]]
+do
+activate="${directory}/bin/activate"
+if [ -e "${activate}" ]
+then
+echo ${directory}
+return 0
+fi
+
+directory=$(dirname ${directory})
+
+done
+return 1
+}
+
+activate-nearest() {
+nearest=$(nearest-venv)
+activate=${nearest}/bin/activate
+if [ -e "${activate}" ]
+then
+. ${activate}
+fi
+}
+
 recreate-venv() {
     # recreate a virtualenv
     VIRTUALENV="virtualenv.py"
@@ -522,6 +555,10 @@
 source ~/.bash_overrides
 
 ### regenerate fluxbox menus here for convenience
+if type deactivate &> /dev/null
+then
+deactivate
+fi
 MENU=~/web/site/programs.html
 regeneratefluxmenu() {
     if [ -e $MENU ]