2

I'm sure this shouldn't be as hard as I'm finding it!

When I log into my machine, i want it to start up a bash shell, in a given directory, open and name some tabs, and start a process in each one.

I think that if i put

cd ~/xxx/xxx/xxx

in .bashrc and then autostart the bash shell with something like

gnome-terminal --tab -e "bash -c 'rails s'" --tab -e "bash -c 'spork'" --tab -e "bash -c 'autotest'" --tab -e "bash -c 'rails c'" --tab -e 'tail -f log/development.log'

it should work

It doesn't - I get "There was an error creating the child process for this terminal Failed to execute child process 'rails' (No such file ...

rails is in the path - both in the root and the destination directories, and giving the full path doesn't help - the terminal window doesn't open.

Update: The reason this doesn't work as expected is that bashrc does not change the working directory until the commands to start the process have been executed. (i can see this if i do tab -e 'pwd')

So the question is really, how can I change directory and then start the processes running?

2
  • Is rails in your path when this script executes? Do you need to give the full path to it?
    – Jez
    Jul 19, 2011 at 9:14
  • thanx jez - updated the question
    – chrispanda
    Jul 19, 2011 at 10:12

2 Answers 2

3

There is a very good solution at:

https://stackoverflow.com/questions/3896882/open-gnome-terminal-programmatically-and-execute-commands-after-bashrc-was-execut

Quoted from link:

Here is a nice trick we worked out at Superuser

  1. Add a eval "$BASH_POST_RC" to the end of your .bashrc

  2. Set the BASH_POST_RC environment variable for each tab to that command you like to execute, e.g.: gnome-terminal --working-directory="/home/zardoz/projects/my_rails_app" --tab -e 'bash -c "export BASH_POST_RC=\"rails server\"; exec bash"' --tab -e 'bash -c "export BASH_POST_RC=\"autotest\"; exec bash"'

@Gilles: Thanks for that solution!

I created the following bash script using this idea.

gnome-terminal --working-directory="/home/USER/rails_projects/PROJECT" --tab --title=Terminal --profile=Rails --tab --profile=Rails --title=Console -e 'bash -c "export BASH_POST_RC=\"rails console\"; exec bash"' --tab --profile=Rails --title=Guard -e 'bash -c "export BASH_POST_RC=\"guard\"; exec bash"' --tab --profile=Rails --title=Server -e 'bash -c "export BASH_POST_RC=\"rails server\"; exec bash"' --tab --profile=Rails --title=Tail -e 'bash -c "export BASH_POST_RC=\"tail -f log/development.log\"; exec bash"'

2

.bashrc isn't invoked when bash called with -c parameter.

Instead you could wrap calling gnome-terminal in script which does cd first. Some like this:

#!/bin/bash
cd ~/xxx/xxx/xxx
gnome-terminal --tab -e "bash -c 'rails s'" --tab -e "bash -c 'spork'" --tab -e "bash -c 'autotest'" --tab -e "bash -c 'rails c'" --tab -e 'tail -f log/development.log'
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .