1

I want make a shell script to startup my project env. I'm using ITerm2 with zsh and oh-my-zsh installed.

I want to:

  1. Open directory
  2. Activate python virtualenv
  3. Run django manage command
  4. Switch to the new tab
  5. change directory
  6. Run gulp command to watch for frontend changes

All I got is this:

#!/bin/zsh
cd ~/Projects/python/project_name
source ~/virtualenvs/project_name/bin/activate
python ./backend/manage.py runserver 
tab
cd front
gulp watch

And as you can expect this doesn't work. Can you point me direction where I should look or is this even possible to do with just shell script?

1 Answer 1

4

Completely possible.

I did pretty much the same thing you're trying (although it is a Rails project) using an NPM package called ttab.

  1. Install NPM.
  2. Install TTab.
  3. You can run the commands in the new tab like so:
# First switch to directory
cd front
# Open new tab in that directory and execute
ttab -G eval "gulp watch"

Note: You can execute several commands if needed, like gulp watch; rails s.

  1. If you need to run a command on the original tab that is also on a different directory, you can create a procedure/function in your script file to do that:
# Define the function before it is called
gotofolder()
{
  cd ~/mydirectory
}

# start the other tabs (...)

# change the original tab directory
gotofolder
# Run Rails or whatever
./bin/rails s

If you want to take a look at how I did this, please checkout the confereai.sh script in my MDFR repo.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi! I found this package too, but I didnt know about functions. Thanks
I'm seing your answer now @jaysoifer but the link to MDFR is not working, if you please update it would be super helpful.
@ŁukaszStaniszewski Bash's functions are explained here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.