Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm using with and so I have say two different directories say:

~/Development/site1
~/Development/site2

So to set up my enviroment I normally go to ~/Development/site1 then run source bin/activate. Is it possible to have that command run automatically when I cd into one of these directories?

share|improve this question
5  
See this recent U&L question: unix.stackexchange.com/questions/21363/… –  enzotib Sep 25 '11 at 16:08
add comment

2 Answers

up vote 3 down vote accepted

You could put this in your .bashrc to redefine the "cd" command:

cd()
{
    [ -z "$*" ] && builtin cd $HOME
    [ -n "$*" ] && builtin cd "$*"
    [ -f "./bin/activate" && source ./bin/activate
}
share|improve this answer
add comment

Would a bash alias suffice? or does it have to be linked to entering the specific directory?

My solution to bash alias.

In ~/.bashrc check that .bash_aliases is ran.

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

In ~/.bash_aliases

alias siteone='cd ~/Development/site1 && source bin/activate'
alias sitetwo='cd ~/Development/site2 && source bin/activate'
share|improve this answer
    
I'll end up doing this instead I think, thanks. I accepted @user25618 answers because it's more correct for the question. –  Kit Sunde Oct 7 '11 at 17:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.